POJ 3258 River Hopscotch 二分枚举
题目:http://poj.org/problem?id=3258
又A一道,睡觉去了。。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <stdio.h> 2 #include <algorithm> 3 4 int d[50010]; 5 int s, n, m; 6 7 bool judge(int mid) 8 { 9 int sum = 0, cnt = 0; 10 for(int i = 1; i <= n+1; i++) 11 { 12 sum += d[i] - d[i-1]; 13 if(sum < mid) 14 cnt++; 15 else 16 sum = 0; 17 } 18 if(cnt > m) 19 return 1; 20 else return 0; 21 } 22 23 int main() 24 { 25 scanf("%d %d %d", &s, &n, &m); 26 for(int i = 1; i <= n; i++) 27 { 28 scanf("%d", &d[i]); 29 } 30 d[0] = 0; 31 d[n+1] = s; 32 std::sort(d, d+n+2); 33 34 int low = 0, high = s+1, mid; 35 while(low < high) 36 { 37 mid = (high + low) / 2; 38 if(judge(mid)) 39 high = mid; 40 else 41 low = mid + 1; 42 } 43 printf("%d\n", low-1); 44 return 0; 45 }