【POJ】[3258]River Hopscotch
2016-04-24 19:53
267 查看
也是一道**化最*值的题
掌握技巧之后这种题还是很简单的
思路都是通过二分来查找答案
然后判断这个答案符不符合要求
这样的话便可以不断二分
来缩小答案所在区间大小
这一题判断答案是否符合的方式
如果最小值是x
那么若想让答案成立
需要去除几个石头
很显然
若想要让答案符合条件
需要去除的石头需要 cnt<=m
通过二分
便可以找到让答案符合的
最大的那个res
#include<stdio.h> #include<algorithm> using namespace std; int a[50200]; int l,n,m; bool judge(int x) { if(x==0) return false; int cnt=0,last=0; for(int i=1; i<n; i++) { int t=a[i]-a[last]; if(t<x) cnt++; else last=i; } if(cnt>m) return false; else return true; } int main() { while(scanf("%d %d %d",&l,&n,&m)!=EOF) { a[0]=0; for(int i=1; i<=n; i++) scanf("%d",&a[i]); a[(++n)++]=l; sort(a,a+n); int la=0,lb=l; int mid,res; while(lb>=la) { mid=(la+lb)/2; if(judge(mid)) { res=mid; la=mid+1; } else lb=mid-1; } printf("%d\n",res); } return 0; }
题目地址:【POJ】[3258]River Hopscotch
相关文章推荐
- 快速排序里的学问:从猜数字开始
- 初学ACM - 组合数学基础题目PKU 1833
- POJ ACM 1001
- POJ ACM 1002
- 1611:The Suspects
- POJ1089 区间合并
- POJ 2635 The Embarrassed Cryptographe
- POJ 3292 Semi-prime H-numbers
- POJ 2773 HAPPY 2006
- POJ 3090 Visible Lattice Points
- POJ-2409-Let it Bead&&NYOJ-280-LK的项链
- POJ-1695-Magazine Delivery-dp
- POJ1523 SPF dfs
- POJ-1001 求高精度幂-大数乘法系列
- POJ-1003 Hangover
- POJ-1004 Financial Management
- 用单调栈解决最大连续矩形面积问题
- HDU 4898 The Revenge of the Princess’ Knight ( 2014 Multi-University Training Contest 4 )
- 2632 Crashing Robots的解决方法
- 1573 Robot Motion (简单题)