标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5253 Accepted Submission(s): 3750
1 #include <cstdio> 2 #include <cmath> 3 4 double f(double x,double y) 5 { 6 return 6*pow(x,7)+8*pow(x,6)+7*pow(x,3)+5*pow(x,2)-y*x; 7 } 8 9 double f1(double x,double y) 10 { 11 return 42*pow(x,6)+48*pow(x,5)+21*pow(x,2)+10*x-y; 12 } 13 14 int main() 15 { 16 int T,y; 17 scanf("%d",&T); 18 while(T--){ 19 scanf("%d",&y); 20 double low = 0,high = 100; 21 while(high-low>1e-6){ 22 double mid = (low+high)/2; 23 if(f1(mid,y)<0) 24 low = mid+1e-8; 25 else 26 high = mid-1e-8; 27 } 28 double x0 = (low+high)/2; 29 printf("%.4f\n",f(x0,y)); 30 } 31 return 0; 32 }
本题也可用三分。
1 #include <cstdio> 2 #include <cmath> 3 4 double f(double x,double y) 5 { 6 return 6*pow(x,7)+8*pow(x,6)+7*pow(x,3)+5*pow(x,2)-y*x; 7 } 8 9 int main() 10 { 11 int T,y; 12 scanf("%d",&T); 13 while(T--){ 14 scanf("%d",&y); 15 double low = 0,high = 100; 16 double lowmid,highmid; 17 while(high-low>1e-6){ 18 lowmid = (2*low+high)/3; 19 highmid = (low+2*high)/3; 20 if(f(lowmid,y)<f(highmid,y)) 21 high = highmid-1e-8; 22 else 23 low = lowmid+1e-8; 24 } 25 printf("%.4f\n",f(low,y)); 26 } 27 return 0; 28 }
标签:
原文地址:http://www.cnblogs.com/inmoonlight/p/5182431.html