hdu2199 二分枚举
这题注意精度就行,其时就是一个简单的二分枚举。[cpp]
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
const double eps=1e-4;
double f(double x)
{
double X[4]={x};
for(int i=1;i<4;i++)
X[i]=x*X[i-1];
return 8*X[3]+7*X[2]+2*X[1]+3*X[0]+6;
}
int main()
{
double x,y,result;
__int64 low,mid,up;
int t;
scanf("%d",&t);
while(t--)
{
scanf("%lf",&y);
if(y<6)
{
printf("No solution!\n");
continue;
}
//刚开始令up=1000000,精度不够,最后在此处纠结了半天
low=0;up=100000000000000;
while(low<=up)
{
mid=(low+up)/2;
x=mid/1000000000000.0;
result=f(x);
if(fabs(result-y)<eps)
break;
if(result<y)
low=mid+1;
else
up=mid-1;
}
if(low<=up)
printf("%.4lf\n",x);
else
printf("No solution!\n");
}
return 0;
}
补充:软件开发 , C++ ,