标签:sed name += math color onclick master http opened
地址 http://poj.org/problem?id=1064
题解 二分即可
其实 对于输入与精度计算不是很在行
老是被卡精度
后来学习了一个函数 floor 向负无穷取整 才能ac
代码如下
1 #include <iostream> 2 #include <vector> 3 #include <math.h> 4 #include <algorithm> 5 6 using namespace std; 7 8 vector<double> v; 9 10 int n, k; 11 12 13 bool check(double m) 14 { 15 int count = 0; 16 for (int i = 0; i < v.size(); i++) 17 { 18 int cut = v[i] / m; 19 count += cut; 20 } 21 22 if (count >= k) return false; 23 24 return true; 25 } 26 27 28 int main() 29 { 30 scanf("%d %d",&n,&k); 31 32 for (int i = 0; i < n; i++) { 33 double t; 34 scanf("%lf",&t); 35 v.push_back(t); 36 } 37 38 sort(v.begin(),v.end()); 39 40 double l = 0.001; double r = v.back(); 41 42 for (int i = 0; i < 1000; i++) { 43 double mid = (l + r) / 2; 44 if (check(mid)) r = mid; 45 else l = mid + 0.0001; 46 } 47 48 printf("%.2f", floor(l*100)/100); 49 return 0; 50 }
标签:sed name += math color onclick master http opened
原文地址:https://www.cnblogs.com/itdef/p/12028283.html