原题传送门:http://poj.org/problem?id=3258
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 6656 | Accepted: 2880 |
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 2 2 14 11 21 17
Sample Output
4
Hint
Source
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define MAXN 50010 #define t 20000000 int st[MAXN]; int flg[MAXN]; int flag[MAXN]; int l,n,m,mid; bool isOK() { int p,k; p = -1; for (int i=1;i<=n;i++) { while (st[i]-st[p+1]>=mid) { p++; } k=p<0?t:min(flg[p],flag[p]); flag[i] = k+i-p-1; flg[i] = min(flag[i-1],flg[i-1])+1; } if (flag[n]<=m) { return true; }else{ return false; } } int main() { scanf("%d%d%d",&l,&n,&m); for (int i=1;i<=n;i++){ scanf("%d",st+i); } st[++n]=l; sort(st+1,st+n); int l=1,r=st[n]; flg[0]=t; flag[0]=0; while (r>=l) { mid=l+r>>1; if (isOK()) { l=mid+1; } else{ r=mid-1; } } printf("%d\n",l-1); return 0; }
相关推荐
北大POJ3258-River Hopscotch 解题报告+AC代码
poj 3050 Hopscotch.md
POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类
poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题...
POJ第1861题源码 POJ第1861题源码 POJ第1861题源码
北大POJ1159-Palindrome 解题报告+AC代码
C语言 poj npu 西工大 C语言Poj答案全完整打包,给有需要的朋友
poj分类poj分类poj分类poj分类
poj 3414解题报告poj 3414解题报告poj 3414解题报告poj 3414解题报告
poj 1012解题报告poj 1012解题报告poj 1012解题报告poj 1012解题报告
poj 2329解题报告poj 2329解题报告poj 2329解题报告poj 2329解题报告
poj 1659解题报告poj 1659解题报告poj 1659解题报告poj 1659解题报告
北大POJ2002-Squares 解题报告+AC代码
POJ1503解答 POJ1503解答,正确答案(已通过POJ)
POJ1048,加强版的约瑟夫问题 难度中等
POJ1083的代码,POJ1083的代码,POJ1083的代码
poj 百练 题目分类 poj 百练 题目分类
poj 1001答案
POJ上的一道题目,自己写的代码,因为想下载别人的, 所以就放上了。
POJ2968代码有用,欢迎下载,POJ代码