HDU 2199 Can you solve this equation?

来源:互联网 发布:微信朋友圈数据采集 编辑:程序博客网 时间:2024/06/05 07:26
#include<cstdio>#include<cmath> #define eps 1e-8double l = 0, r = 100, mid, y, ans;double f(double x){return 8 * pow(x, 4) + 7 * pow(x, 3) + 2 * pow(x, 2) + 3 * x + 6;}int main(){int T;scanf("%d", &T);while (T--){l=0;r=100;scanf("%lf", &y);if (f(l)>y || f(r)<y)   //因为该函数在[0,100]上递增{printf("No solution!\n");continue;}while (r-l>eps){mid = (l + r) / 2;if (f(mid)>y)  r = mid;if (f(mid)<y)  l = mid;}printf("%.4f\n", l);}return 0;}



原创粉丝点击