标签:size IV ali 牛顿迭代 ons BMI panel pac mission
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 9333 Accepted Submission(s):
6352
#include<cstdio> #include<cmath> #include<algorithm> using namespace std; const double eps = 1e-9; double y; double fdd(double x) { return 252 * pow(x, 5) + 240 * pow(x, 4) + 42 * x + 10; } double fd(double x) { return 42 * pow(x, 6) + 48 * pow(x, 5) + 21 * pow(x, 2) + 10 * x - y; } double f(double x) { return 6 * pow(x, 7) + 8 * pow(x, 6) + 7 * pow(x, 3) + 5 * pow(x, 2) - y * x; } double Newton(double x) { while(fabs(fd(x)) > eps) x = x - fd(x) / fdd(x); return x; } int main() { int QwQ; scanf("%d", &QwQ); while(QwQ--) { scanf("%lf", &y); double ans = 1e15, pos; for(int i = 0; i <= 100; i++) { double anspos = Newton(i); if(anspos >= 0 && anspos <= 100) ans = min(ans, f(anspos)); } printf("%.4lf\n", ans); } return 0; }
HDU 2899 Strange fuction(牛顿迭代)
标签:size IV ali 牛顿迭代 ons BMI panel pac mission
原文地址:https://www.cnblogs.com/zwfymqz/p/9149347.html