爬山问题
爬山问题 第n个山峰的坐标很好求,问题是什么情况下看不到呢?直觉需要斜率的动态比较 山峰的高度和山谷的深度形成的数列是这个:https://oeis.org/A008347
山峰好像是上凸的,能看到的基本上都是近处的山峰,远处的山峰好像基本上都看不到 从复杂度来说,对于现在的计算机,$10^5$不大,直接计算每个点同后面所有点的仰角并进行比较是否超过当前已知最大仰角即可。
当然从效率上,应该需要考虑Fans提到的基本上都是近峰的问题,所以可以缩小计算数目。如果当前仰角正切值已经大于后面最大素数gap/两素数和,那么就不需要继续搜索了,不知道这个裁剪效率如何 本帖最后由 iseemu2009 于 2025-3-11 11:34 编辑
下面的程序计算前15个山峰的坐标
zb := {Total]],
Total, {i, 2 n - 1}]]};(*计算第n个峰顶的坐标*)
dianji = Table, {i, 15}](*计算前15个峰顶(点集)的坐标*)
{2, 2}, {10, 4}, {28, 8}, {58, 12}, {100, 16}, {160, 18}, {238, 22}, {328, 26}, {440, 32}, {568, 38}, {712, 40}, {874, 44}, {1060, 52}, {1264, 54}, {1480, 56} 52462
#include <stdio.h>
#include <stdlib.h>
#define MAXP 2750200L
#ifndef MPS
#define MPS 20000
#endif
unsigned char notp;
int pc;
long plist;
long sumf;
long sumg;
int maxslop;
#define ISPRIME(x) (!notp)
#define UNSETPRIME(x) (notp=1)
void initp()
{
UNSETPRIME(0);
UNSETPRIME(1);
long i;
plist=0;//add an extra number 0 at the beginning
for(i=2;i<MAXP;i++){
if(ISPRIME(i)){
long j;
plist=i;
if(pc>=MPS)break;
for(j=i*i;j<MAXP;j+=i)UNSETPRIME(j);
}
}
if(pc<MPS){
fprintf(stderr,"Prime not enough\n");
exit(-1);
}
sumf=plist+plist;
sumg=plist-plist;
maxslop=MPS/2-1;
for(i=MPS/2-2;i>=0;i--){
sumf=plist+plist;
sumg=plist-plist;
if(sumg*sumf]>sumg]*sumf){
maxslop=i;
}else{
maxslop=maxslop;
}
}
}
int main()
{
int i,j;
long tsum=0;
long bx=0,by=0;
initp();
for(i=0;i<MPS/2-1;i++){
long fx=sumf;
long fy=sumg;
bx=fx;by=fy;
long cc=1;
for(j=i+2;j<MPS/2;j++){
if(by*sumf]>=bx*sumg])break;
fx+=sumf;
fy+=sumg;
if(fx*by<bx*fy){//higher than best
cc++;
by=fy;bx=fx;
}
}
tsum+=cc;
}
printf("%ld\n",tsum);
return 0;
}
页:
[1]