2 100 200
-74.4291 -178.8534
#include <map> #include <set> #include <list> #include <stack> #include <queue> #include <vector> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; int main() { int t; scanf("%d\n", &t); while (t--) { double y; scanf("%lf", &y); if (y <= 0) { printf("0.0000\n"); continue; } double l = 0, r = 100, mid; while(r - l > 1e-6) { mid = (l + r) / 2; double dx = 42.0 * pow(mid, 6) + 48.0 * pow(mid, 5) + 21.0 * pow(mid, 2) + 10.0 * mid; if (abs(dx - y) < 1e-6) { break; } else if(dx - y > 1e-6) { r = mid; } else { l = mid; } } if (mid - 100.0 > 1e-6) { mid = 100.0; } double ans = 6 * pow(mid, 7) + 8 * pow(mid, 6) + 7 * pow(mid, 3) + 5 * pow(mid, 2) - y * mid; printf("%.4f\n", ans); } return 0; }
原文地址:http://blog.csdn.net/guard_mine/article/details/40894283