标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4603 Accepted Submission(s): 3308
1 #include <cstdio> 2 #include <iostream> 3 using namespace std; 4 double f(double x, double y) 5 { 6 return 6*x*x*x*x*x*x*x+8*x*x*x*x*x*x+7*x*x*x+5*x*x-y*x; 7 } 8 int main() 9 { 10 int t; double m; 11 scanf("%d", &t); 12 while(t--) 13 { 14 scanf("%lf", &m); 15 double l_min, r_max, min = 0.0, max = 100.0; 16 // printf("%.4lf %.4lf\n", min, max); 17 while(max - min > 1e-8) 18 { 19 l_min = (2 * min + max) / 3.0; 20 r_max = (min + 2 * max) / 3.0; 21 if(f(l_min, m)>f(r_max, m)) min = l_min; 22 else max = r_max; 23 } 24 // printf("%.4lf %.4lf\n", min, max); 25 printf("%.4lf\n",f((min + max) / 2.0, m)); 26 } 27 return 0; 28 }
//闲来无事, 敲敲手生的二分(大同小异, 一个比较值, 一个比较导数);
1 #include <cstdio> 2 #include <iostream> 3 using namespace std; 4 double f(double x, double y) 5 { 6 return 42*x*x*x*x*x*x+48*x*x*x*x*x+21*x*x+10*x-y; 7 } 8 double F(double x, double y) 9 { 10 return 6*x*x*x*x*x*x*x+8*x*x*x*x*x*x+7*x*x*x+5*x*x-y*x; 11 } 12 int main() 13 { 14 int t; 15 scanf("%d", &t); 16 while(t--) 17 { 18 double m, min = 0.0, max = 100.0, mid; 19 scanf("%lf", &m); 20 while(max - min > 1e-8) 21 { 22 mid = (max + min) / 2.0; 23 if(f(mid, m) <= 0) min = mid; 24 else max = mid; 25 } 26 printf("%.4lf\n", F((min + max) / 2.0 , m)); 27 } 28 return 0; 29 }
标签:
原文地址:http://www.cnblogs.com/fengshun/p/4701939.html