标签:others nbsp content binary cas sam 左右 lines which
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 19647 Accepted Submission(s): 8664
注意控制精度,不然会超时,虽然是保留四位小数,但是精度得10的-8次方左右
1 #include<iostream> 2 #include<stdio.h> 3 #define exp 1e-8 4 using namespace std; 5 6 double key; 7 8 double Binary(double low,double high) 9 { 10 while(high-low>exp) 11 { 12 double mid = (low+high)/2; 13 if(8*mid*mid*mid*mid + 7*mid*mid*mid + 2*mid*mid + 3*mid + 6 > key) 14 high=mid-exp; 15 else 16 low=mid+exp; 17 } 18 return low; 19 } 20 int main() 21 { 22 int t; 23 scanf("%d",&t); 24 while(t--) 25 { 26 scanf("%lf",&key); 27 if(6>key || 8*100*100*100*100 + 7*100*100*100 + 2*100*100 + 3*100 + 6 < key) 28 printf("No solution!\n"); 29 else 30 printf("%.4f\n",Binary(0, 100)); 31 } 32 return 0; 33 }
标签:others nbsp content binary cas sam 左右 lines which
原文地址:http://www.cnblogs.com/Xycdada/p/6711489.html