这B题牛顿迭代过不了
这B题标程是三分还是牛顿迭代。我用牛顿迭代过了%75数据,是不是精度问题,按说牛顿迭代精度更高,基本完爆三分才对。
#include<bits/stdc++.h> //#include<windows.h> using namespace std; #define ll long long #define inf 1e-7 const int inv2=500000004; const int INF=2147483647;////2139062143 const int MAX=1000010; const int mod=1e9+7; const double in2=log(2); int a=1,b=1,c=1,d=1,e=1; double Fx(double x){ double l2=log2(x); return a*x*x+b*x+c+d*l2*l2+e*l2; } double fx(double x){ return 2*a*x*x*in2+b*x*in2+(2*d*log2(x)+e); } double f_x(double x){ return 4*a*x*in2+b*in2+2*d/(x*in2); } double niu(){ double x=1,prex=0; int k=50; while(fabs(prex-x)>1e-15 && x>1e-7){//&& !isnanf(x) prex=x; x=x-fx(x)/f_x(x); } x=max(x,1e-7); return x; } int main(int argc,char *argv[]){ int i,j,k,t,T,n,m; //printf("%lf",log2(0)); cin>>T; while(T--){ scanf("%d",&m); while(m--){ scanf("%d%d%d%d%d",&a,&b,&c,&d,&e); if(d==0&&e==0){ printf("%.8lf\n",Fx(1e-7)); }else if(d==0&&e>0){ printf("INF\n"); }else{ double x=niu(); printf("%.20lf\n",x); printf("%.8lf\n",Fx(x)); } } } return 0; } /* 111 55 0 0 0 1 100 100 100 100 100 100 0 0 1 1 0 1 1 1 0 0 0 0 1 0 0 -1784.57965044 */