POJ3258 River Hopscotch(二分法求最大化最小值)
来源:互联网 发布:mysql int字段累加 编辑:程序博客网 时间:2024/06/07 02:33
Link:http://poj.org/problem?id=3258
Description
Every year the cows hold an event featuring a peculiar version of hopscotch that involves carefully jumping from rock to rock in a river. The excitement takes place on a long, straight river with a rock at the start and another rock at the end, L units away from the start (1 ≤ L ≤ 1,000,000,000). Along the river between the starting and ending rocks, N (0 ≤ N ≤ 50,000) more rocks appear, each at an integral distance Di from the start (0 < Di < L).
To play the game, each cow in turn starts at the starting rock and tries to reach the finish at the ending rock, jumping only from rock to rock. Of course, less agile cows never make it to the final rock, ending up instead in the river.
Farmer John is proud of his cows and watches this event each year. But as time goes by, he tires of watching the timid cows of the other farmers limp across the short distances between rocks placed too closely together. He plans to remove several rocks in order to increase the shortest distance a cow will have to jump to reach the end. He knows he cannot remove the starting and ending rocks, but he calculates that he has enough resources to remove up to M rocks (0 ≤ M ≤ N).
FJ wants to know exactly how much he can increase the shortest distance *before* he starts removing the rocks. Help Farmer John determine the greatest possible shortest distance a cow has to jump after removing the optimal set of M rocks.
Input
Lines 2..N+1: Each line contains a single integer indicating how far some rock is away from the starting rock. No two rocks share the same position.
Output
Sample Input
25 5 2214112117
Sample Output
4
Hint
Source
AC code:
#include<iostream>#include<stdio.h>#include<algorithm>#include<math.h>#include<string.h>#include<map>#include<set>#define LL long long#define INF 0xfffffffusing namespace std;int rock[50010];int L,N,M;int group(int mid){int delnum=0,dis=0,i;for(i=1;i<=N+1;i++){dis+=rock[i]-rock[i-1];if(dis<=mid){delnum++;}else{dis=0;}}return delnum;}int Bsearch(int low,int high){int mid;while(low<=high){mid=(low+high) >> 1;if(group(mid)>M)//要删除的砖块数量比M多,说明限制的最小值mid偏大了 {high=mid-1;}else{low=mid+1; }}return low;}int main(){//freopen("in.txt","r",stdin);int i,low,high,ans; while(scanf("%d%d%d",&L,&N,&M)!=EOF){for(i=1;i<=N;i++){scanf("%d",&rock[i]);}rock[0]=0;rock[N+1]=L; sort(rock,rock+N+2);low=0;high=L;ans=Bsearch(low,high);printf("%d\n",ans);}return 0;}
- POJ3258 River Hopscotch(二分法求最大化最小值)
- POJ3258 River Hopscotch(最大化最小值/二分法)
- (最大化最小值),poj3258,River Hopscotch
- POJ3258-River Hopscotch-二分+贪心【最小值最大化】
- POJ3258:River Hopscotch(二分法)
- (POJ3258)River Hopscotch <二分法>
- 【二分法】POJ3258-River Hopscotch
- poj 3258 River Hopscotch(二分法,最小值最大化)
- River Hopscotch poj3258 (二分+贪心思想+最小值最大化)
- poj_3258 River Hopscotch(二分求最大化最小值)
- POJ3258—River Hopscotch—二分法求the largest mimmun
- POJ 3258 River Hopscotch(最大化最小值)
- poj3258--River Hopscotch(二分)
- POJ3258 River Hopscotch(二分)
- POJ 3258-River Hopscotch(二分法-最大化最短距离)
- River Hopscotch(二分法)
- POJ - 3258 River Hopscotch(二分搜索:最大化最小值)
- [ACM] POJ 3258 River Hopscotch (二分,最大化最小值)
- (三十二)ToolBar 与 SearchView
- 巩固与修炼(八)
- 同一张html页面点击出现弹出框
- git 协作开发常规操作
- 设计模式
- POJ3258 River Hopscotch(二分法求最大化最小值)
- 设计模式-前摄器模式(Proactor)
- ios+Android老程序员的下场
- VLAN内的报文转发
- 数据结构--串 KMP匹配
- IDS验证(正整数并且是逗号分隔)
- 【Java】线程安全学习
- 探探左滑右滑, OKHttp请求网络数据实现
- 在web.xml中,<context-param>标签的作用是什么?