标签:and not The class sign region sig 代码 等于
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 65116 | Accepted: 13414 |
Description
Input
Output
Sample Input
4 11 8.02 7.43 4.57 5.39
Sample Output
2.00
1 #include <cstdio> 2 #include <cctype> 3 #include <algorithm> 4 #include <cmath> 5 #define num s-‘0‘ 6 7 using namespace std; 8 9 const int MAX_N=100000; 10 const int INF=100000; 11 int n,k; 12 double L[MAX_N]; 13 14 void read(int &x){ 15 char s; 16 x=0; 17 bool flag=0; 18 while(!isdigit(s=getchar())) 19 (s==‘-‘)&&(flag=true); 20 for(x=num;isdigit(s=getchar());x=x*10+num); 21 (flag)&&(x=-x); 22 } 23 24 void write(int x) 25 { 26 if(x<0) 27 { 28 putchar(‘-‘); 29 x=-x; 30 } 31 if(x>9) 32 write(x/10); 33 putchar(x%10+‘0‘); 34 } 35 36 double search(); 37 bool C(double x); 38 39 int main() 40 { 41 read(n);read(k); 42 for (int i=0; i<n; i++) scanf("%lf", &L[i]); 43 double p = search(); 44 printf("%.2f", floor(p*100)/100); 45 putchar(‘\n‘); 46 } 47 48 bool C(double x) 49 { 50 int sum=0; 51 for (int i=0; i<n; i++) 52 { 53 sum+=(int)(L[i]/x); 54 if (sum>=k) return true; 55 } 56 return false; 57 } 58 59 double search() 60 { 61 double lb=0, ub=INF; 62 //while (ub-lb>0.001) 63 for (int i=0; i<100; i++) 64 { 65 double mid=(lb+ub)/2; 66 if (C(mid)) lb=mid; 67 else ub=mid; 68 } 69 return ub; 70 }
标签:and not The class sign region sig 代码 等于
原文地址:https://www.cnblogs.com/Ymir-TaoMee/p/9496341.html