标签:which cep hdu when ssi include sam names namespace
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 7230 Accepted Submission(s): 4996
1 #include<iostream> 2 #include<stdio.h> 3 #include<math.h> 4 #define exp 1e-8 5 6 using namespace std; 7 8 double y; 9 10 double suan(double x) 11 { 12 return 42*pow(x,6)+48*pow(x,5)+21*x*x+10*x-y; 13 } 14 double binary(double low,double high) 15 { 16 while(high-low>exp) 17 { 18 double mid = (low+high)/2; 19 if(suan(mid)>0) 20 high=mid-exp; 21 else 22 low=mid+exp; 23 } 24 return low; 25 } 26 int main() 27 { 28 int t; 29 scanf("%d",&t); 30 while(t--) 31 { 32 scanf("%lf",&y); 33 double ans = binary(0,100); 34 printf("%.4f\n",6*pow(ans,7)+8*pow(ans,6)+7*pow(ans,3)+5*ans*ans-y*ans); 35 } 36 return 0; 37 }
三分查找
1 #include<iostream> 2 #include<stdio.h> 3 #include<math.h> 4 #define exp 1e-8 5 6 using namespace std; 7 8 double y; 9 10 double suan(double x) 11 { 12 return 6*pow(x,7)+8*pow(x,6)+7*pow(x,3)+5*x*x-y*x; 13 } 14 double binary(double low,double high) 15 { 16 double mid,mmid; 17 while(high-low>exp) 18 { 19 mid = (low+high)/2; 20 mmid = (high+mid)/2; 21 if(suan(mid)>suan(mmid)) 22 low=mid+exp; 23 else 24 high=mmid-exp; 25 } 26 return (mid+mmid)/2; 27 } 28 int main() 29 { 30 int t; 31 scanf("%d",&t); 32 while(t--) 33 { 34 scanf("%lf",&y); 35 double ans = binary(0,100); 36 printf("%.4f\n",suan(ans)); 37 } 38 return 0; 39 }
标签:which cep hdu when ssi include sam names namespace
原文地址:http://www.cnblogs.com/Xycdada/p/6713029.html