标签:
题意:输入y的值,则求出方程8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y的解,若有解,则该解一定在[0, 100]之间,输出x,若无解则输出No solution!。
#include<stdio.h> #include<math.h> int main () { double a, b, c, y, sum, d; int T, x; scanf("%d", &T); while (T--) { scanf("%lf", &y); x = 0; a = 0; b = 100; d = 8*b*b*b*b + 7*b*b*b + 2*b*b + 3*b + 6; c = 8*a*a*a*a + 7*a*a*a + 2*a*a + 3*a + 6; if (y >= c && y <= d) x = 1; if (x) { while (b-a > 1e-6) ///浮点数判断b是否大于a { c = (a+b)/2; sum = 8*c*c*c*c + 7*c*c*c + 2*c*c + 3*c + 6; if (sum > y) b = c-1e-7; else a = c+1e-7; } printf("%.4lf\n", (a+b)/2); } if (x == 0) printf("No solution!\n"); } return 0; }
HDU 2199 Can you solve this equation?(水题吗?!)
标签:
原文地址:http://www.cnblogs.com/syhandll/p/4780909.html