题目链接:Click
here~~
二分查找。注意精度。
#include <stdio.h> #include <math.h> double f(double x) { return 8*pow(x,4) - 7*pow(x,3) + 2*pow(x,2) + 3*x + 6; } double Binary_Find(double left,double right,double y) { while(right-left>1e-7) { double mid=(left+right)/2; if(f(mid) < y) left = mid; else right = mid; } return left; } int main() { int z; double y; scanf("%d",&z); while(z--) { scanf("%lf",&y); if(f(0)>y || f(100)<y) puts("No solution!"); else printf("%.4lf\n",Binary_Find(0,100,y)); } return 0; }