River Hopscotch POJ - 3258 (二分求最小值)
2017-04-21 10:07
253 查看
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> using namespace std; const int maxn = 50005; int a[maxn]; int n,L,m; int ok(int mid) { int dis=0,num=0; for(int i=0;i<n;i++) { if(a[i]-dis<mid) {num++;} else dis=a[i]; } if(L-dis<mid) num++; if(num<=m) return 1;//因为要求最大值,如果=放在下面的话,范围就变小了 else return 0; } int main() { scanf("%d %d %d",&L,&n,&m); for(int i=0;i<n;i++) scanf("%d",&a[i]); sort(a,a+n); int l=0,r=L,res=0; while(l<=r) { int mid=l+(r-l)/2; if(!ok(mid)) {r=mid-1;} else {res=mid;l=mid+1;} } printf("%d\n",res); return 0; }
相关文章推荐
- 【POJ】3258 - River Hopscotch 二分->最大化最小值
- River Hopscotch POJ - 3258 (二分求最小值)
- River Hopscotch POJ - 3258 (二分求最小值)
- River Hopscotch POJ - 3258 (二分求最小值)
- River Hopscotch POJ - 3258 (二分求最小值)
- POJ_3258_River_Hopscotch_[NOIP2015]_(二分,最大化最小值)
- River Hopscotch POJ - 3258 (二分求最小值)
- River Hopscotch POJ - 3258 (二分求最小值)
- POJ 3258 River Hopscotch【二分:最大化最小值】
- River Hopscotch POJ - 3258 (二分求最小值)
- POJ 3258 River Hopscotch【二分搜索】
- POJ_3258_River Hopscotch_二分搜索
- River Hopscotch - POJ 3258 二分
- poj 3258:River Hopscotch(二分)
- POJ 3258 River Hopscotch 经典二分
- POJ 3258 River Hopscotch 二分
- POJ - 3258 River Hopscotch 二分
- POJ 3258 River Hopscotch 二分
- POJ 3258 River Hopscotch 二分搜索
- POJ 3258:River Hopscotch & POJ 3273:Monthly Expense (二分)