题目链接:http://poj.org/problem?id=1064
卡精度…恶心了很久很久最终还是过了,真是各种姿势啊。。。
1 #include <algorithm> 2 #include <iostream> 3 #include <iomanip> 4 #include <cstring> 5 #include <climits> 6 #include <complex> 7 #include <fstream> 8 #include <cassert> 9 #include <cstdio> 10 #include <bitset> 11 #include <vector> 12 #include <deque> 13 #include <queue> 14 #include <stack> 15 #include <ctime> 16 #include <set> 17 #include <map> 18 #include <cmath> 19 20 using namespace std; 21 22 const double eps = 1e-15; 23 const int maxn = 10010; 24 const int INF = 1 << 30; 25 26 int n, k; 27 double line[maxn]; 28 29 bool ok(double x) { 30 int cnt = 0; 31 for(int i = 0; i < n; i++) { 32 cnt += int(line[i] / x); 33 } 34 return cnt >= k; 35 } 36 37 int main() { 38 // freopen("in", "r", stdin); 39 while(~scanf("%d %d", &n, &k)) { 40 for(int i = 0; i < n; i++) { 41 scanf("%lf", &line[i]); 42 } 43 double ll = 0, rr = INF; 44 // while(rr - ll > eps) { 45 // double mm = (ll + rr) / 2; 46 // if(ok(mm)) { 47 // ll = mm; 48 // } 49 // else { 50 // rr = mm; 51 // } 52 // } 53 for(int i = 0; i < 100; i++) { 54 double mm = (ll + rr) / 2; 55 if(ok(mm)) { 56 ll = mm; 57 } 58 else { 59 rr = mm; 60 } 61 } 62 printf("%.2lf ",floor(rr * 100) / 100); 63 } 64 }