标签:
# include <iostream> # include <cmath> using namespace std; double f(double x, double y) { double fx = 42 * pow(x, 6) + 48 * pow(x, 5) + 21 * pow(x, 2) + 10 * x - y; return fx; } double f1(double x, double y) { double fx = 6 * pow(x, 7) + 8 * pow(x, 6) + 7 * pow(x, 3) + 5 * pow(x, 2) - y * x; return fx; } int main() { int t; cin >> t; while(t--) { double y; cin >> y; double begin = 0, end = 100, mid; int i = 0; while(1) { mid = (begin + end) / 2; if(fabs(f(mid, y)) <= 0.0001) { cout.precision(4); cout << fixed << f1(mid, y) << endl; break; } else if(f(mid, y) > 0) { end = mid; } else if(f(mid, y) < 0) { begin = mid; } } } return 0; }
标签:
原文地址:http://www.cnblogs.com/lyf-acm/p/5387439.html