标签:
简单题意:
给出一个方程,求解方程,注意Y的范围。
思路:
用二分法求解,
# include <iostream> # include <cmath> using namespace std; double f(double x, double y) { double fx = 8 * pow(x, 4) + 7 * pow(x, 3) + 2 * pow(x, 2) + 3 * x + 6 - y; 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) { if(y < 6 || y > 8.0702e+8) { cout << "No solution!" << endl; break; } mid = (begin + end) / 2; if(fabs(f(mid, y)) <= 0.0001) { cout.precision(4); cout << fixed << mid << endl; break; } else if(f(mid, y) > 0) { end = mid; } else if(f(mid, y) < 0) { begin = mid; } //cout << mid << endl; } } return 0; }
HDU 搜索练习 Can you solve this equation?
标签:
原文地址:http://www.cnblogs.com/lyf-acm/p/5387393.html