关于计算函数值时的疑似精度错误

P3382 三分

这精度差的有点大吧。 我能看下完整代码吗?
by mashduihca @ 2023-03-10 14:06:23


单纯三分写挂了而已。
by Usada_Pekora @ 2023-03-10 14:08:31


@[Usada_Pekora](/user/434929) 我的三分写法使用的就是这个函数,过了.
by ProzacPainkiller @ 2023-03-11 09:30:09


@[mashduihca](/user/494183) 麻烦您了. ```cpp #include<bits/stdc++.h> #define rand01 ((rand()%1000+1)/1000.0) using namespace std; const double eps=1e-6,cold=0.99995; int n; double l,r,a[15]; double f(double x) { double ans=0; for(int i=n;i>=0;i--) { ans*=x; ans+=a[i]; } return ans; } int main() { cin>>n>>l>>r; srand(170001); for(int i=n;i>=0;i--) cin>>a[i]; double t=1114,now=l; while(t>eps) { double dt,to=l+(r-l)*rand01; dt=f(to)-f(now); if(dt>=0||exp(dt/t)>rand01) now=to; t*=cold; } printf("%.6f",now); return 0; } ```
by ProzacPainkiller @ 2023-03-11 09:30:57


写的模拟退火
by ProzacPainkiller @ 2023-03-11 09:32:09


话说真的有人还会看吗()
by ProzacPainkiller @ 2023-03-11 09:34:49


@[eggome](/user/569484) 你的rand太差了。你的那个rand01宏的精度最多0.001,导致你取到的函数值必定形如l+一个(r-l)*0.001的整数倍。 建议使用uniform_real_distribution生成更好的随机浮点数。 另外我觉得你这个退火写的也有问题。其实你写的不是退火。
by mashduihca @ 2023-03-11 09:59:17


@[mashduihca](/user/494183) o,谢谢了
by ProzacPainkiller @ 2023-03-11 10:07:17


|