River Hopscotch(二分)
2013-10-11 21:08
162 查看
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 5473 | Accepted: 2379 |
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 Mrocks (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 ofM rocks.
Input
Line 1: Three space-separated integers: L, N, and M
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
Line 1: A single integer that is the maximum of the shortest distance a cow has to jump after removing M rocks
Sample Input
25 5 2 2 14 11 21 17
Sample Output
4 输入L,N,M;L表示终点离起点的距离,从起点到终点有N块石头(不包含起点和终点),要求移除M块石头后,使得那时的最短距离尽可能的大,并输出这个距离; 类似于poj3273;
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; const int N = 50000; int l,n,m; int rock[N+10]; int low,high,mid; bool judge(int mid) { int sum = 0; int group = 0; for(int i = 1; i <= n+1; i++) { if(sum + (rock[i]-rock[i-1]) <= mid) { sum += rock[i]-rock[i-1]; group++; } else { sum = 0; } } if(group > m) return false; return true; } int main() { scanf("%d %d %d",&l,&n,&m); rock[0] = 0; rock[n+1] = l; low = l; high = l; for(int i = 1; i <= n+1; i++) { if(i <= n) scanf("%d",&rock[i]); if(low > rock[i]-rock[i-1]) low = rock[i]-rock[i-1]; } sort(rock,rock+(n+2)); while(low <= high) { mid = (low+high)/2; if(!judge(mid)) high = mid-1; else low = mid+1; } printf("%d\n",low); return 0; }
View Code
相关文章推荐
- Linux设备驱动01
- Linux安装与配置ftp服务器
- linux下音频编程
- Tomcat发布网站知识集锦
- linux下pthread_exit在主线程中的用途
- Red hat linux ping: unknown host www.baidu.com
- WIN7 VS2010配置Openssl
- 用rapid-framework开源工具快速生成SSH的网站框架MVC模式
- 漫谈SOA(面向服务架构)
- Shell 脚本学习资料搜集
- Linux常用命令大全
- Linux VirtualBox中实现文件夹共享 .
- ArchLinux Kernel driver not installed .
- Linux就是这个范儿之第一次亲密接触(3)
- Shell 单引号 双引号 反引号
- Servlet+Tomcat 界面登录
- Linux kernel 内存损坏漏洞
- Linux kernel get_prng_bytes函数数字错误漏洞
- linux 内存释放 (转)
- shell 脚本 睡眠