POJ 3258 River Hopscotch 解题报告(二分)
2013-08-07 11:37
411 查看
题目大意:一串上升数,问你去掉m个数字后,相邻数的最大的最小差是多少。
解题报告:二分。再一次感受到二分的强大。要找的是最大的符合条件的数,那么我找最小的不符合条件的数,-1就ok啦。
解题报告:二分。再一次感受到二分的强大。要找的是最大的符合条件的数,那么我找最小的不符合条件的数,-1就ok啦。
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; int d[500010]; int l,r,n,m; bool judge(int mid) { int num=0; int last=0; for(int i=1;i<=n;i++) { if(d[i]-last<mid) num++; else last=d[i]; } return num>m; } int main() { scanf("%d%d%d",&r,&n,&m); d[++n]=r; for(int i=1;i<n;i++) scanf("%d",d+i); sort(d+1,d+n); l=0; while(l<=r) { int mid=(l+r)>>1; if(judge(mid)) r=mid-1; else l=mid+1; } printf("%d\n",r); }
相关文章推荐
- POJ-3258 River Hopscotch 解题报告(二分) 牛跳石头
- POJ-3258 River Hopscotch 解题报告
- POJ-3258___River Hopscotch——解题报告 二分法
- POJ-3258 River Hopscotch 解题报告
- River Hopscotch POJ - 3258 (二分求最小值)
- POJ-3258 River Hopscotch 二分枚举求上限
- River Hopscotch POJ - 3258 (二分求最小值)
- POJ 3258 River Hopscotch 二分搜索
- Poj3258 River Hopscotch 二分
- poj 3258 River Hopscotch 【二分】
- POJ 3258 River Hopscotch 二分
- 【POJ】3258 - River Hopscotch 二分->最大化最小值
- River Hopscotch POJ - 3258 (二分求最小值)
- 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 二分