标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)
Total Submission(s): 5676 Accepted Submission(s): 2732
#include <cstdio> #include <iostream> #include <algorithm> using namespace std; const int INF= 0x3f3f3f3f ; int d[550000]; int L; int calc(int x) { int now=0; int cnt=0; int ps=0; while(now< L) { now+= x; while(now >=d[ps+1]) ps++; now=d[ps]; cnt++; } return cnt; } int main() { int n, m; while(scanf("%d%d%d", &L, &n, &m) != EOF) { int minx =0 ; for(int i=1; i<= n; i++) scanf("%d", &d[i]); sort(d+1, d+1+n); d[0]= 0; d[n+1]= L; d[n+2]= INF ; for(int i=1; i<= n+1; i++) if(minx <d[i]- d[i-1]) minx= d[i]- d[i-1]; int left= minx, right= L; int res; while(left <= right){ int mid= (left+right)>> 1; if(calc(mid) <= m) { res= mid; right= mid-1; } else left= mid+1; } printf("%d\n", res); } return 0; }
hdoj 4004 The Frog's Games(二分)
标签:
原文地址:http://www.cnblogs.com/fengshun/p/5524845.html