poj3258River Hopscotch
http://poj.org/problem?id=3258
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<stdlib.h> 5 #include<cmath> 6 #include<algorithm> 7 using namespace std; 8 int st[50010],di[50010],n,m; 9 int judge(int mi) 10 { 11 int i,k=0,s=0; 12 for(i = 1; i <= n+1 ; i++) 13 { 14 s+=di[i]; 15 if(s<mi) 16 k++; 17 else 18 s = 0; 19 } 20 if(k>m) 21 return 1; 22 else 23 return 0; 24 } 25 int main() 26 { 27 int i,ll; 28 while(cin>>ll>>n>>m) 29 { 30 for(i = 1; i <= n ; i++) 31 { 32 cin>>st[i]; 33 } 34 st[0] = 0;st[n+1] = ll; 35 sort(st,st+n+2); 36 int low = ll,high = ll; 37 for(i = 1; i <= n+1 ; i++) 38 { 39 di[i] = st[i]-st[i-1]; 40 if(low>di[i]) 41 low = di[i]; 42 } 43 int mid = (low+high)/2; 44 while(low<=high) 45 { 46 if(judge(mid)) 47 high = mid-1; 48 else 49 low = mid+1; 50 mid = (low+high)/2; 51 } 52 cout<<mid<<endl; 53 } 54 return 0; 55 }