River Hopscotch(二分POJ3258)
River Hopscotch
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 9263 Accepted: 3994
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
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
Hint
Before removing any rocks, the shortest jump was a jump of 2 from 0 (the start) to 2. After removing the rocks at 2 and 14, the shortest required jump is a jump of 4 (from 17 to 21 or from 21 to 25).
题意:
一条河中有一些石头,给你这些石头距离起点的距离,和河的宽度,问移去m块石头后,剩余石头之间距离的最小距离的最大值.
思路:
二分石头的最小距离,判断这个距离需要移动的石头的数目,不断的进行二分找到一个最大值.
#include <set>
#include <map>
#include <list>
#include <stack>
#include <cmath>
#include <vector>
#include <queue>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define PI cos(-1.0)
#define RR freopen("input.txt","r",stdin)
using namespace std;
typedef long long LL;
const int MAX = 50010;
LL Arr[MAX];
int n,m;
LL l;
bool Judge(LL s)
{
LL ans=0;
int num=0;
for(int i=0;i<=n;i++)
{
if(ans+Arr[i+1]-Arr[i]>=s)
{
ans=0;
}
else
{
num++;
ans+=(Arr[i+1]-Arr[i]);
}
if(num>m)
{
return false;
}
}
return true;
}
int main()
{
while(~scanf("%lld %d %d",&l,&n,&m))
{
for(int i=1;i<=n;i++)
{
scanf("%lld",&Arr[i]);
}
Arr[0]=0;
Arr[n+1]=l;
sort(Arr,Arr+n+1);
LL L=0,R=l;
LL ans=0;
while(L<=R)
{
LL mid=(L+R)>>1;
if(Judge(mid))
{
ans=max(ans,mid);
L=mid+1;
}
else
{
R=mid-1;
}
}
printf("%lld\n",ans);
}
return 0;
}
River Hopscotch(二分POJ3258)的更多相关文章
- POJ3258 River Hopscotch —— 二分
题目链接:http://poj.org/problem?id=3258 River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total ...
- POJ 3258 River Hopscotch(二分答案)
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 21939 Accepted: 9081 Desc ...
- [ACM] POJ 3258 River Hopscotch (二分,最大化最小值)
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6697 Accepted: 2893 D ...
- POJ 3258:River Hopscotch 二分的好想法
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9326 Accepted: 4016 D ...
- G - River Hopscotch(二分)
Every year the cows hold an event featuring a peculiar version of hopscotch that involves carefully ...
- River Hopscotch(二分)
Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5473 Accepted: 2379 Description Every ...
- poj 3258 River Hopscotch(二分+贪心)
题目:http://poj.org/problem?id=3258 题意: 一条河长度为 L,河的起点(Start)和终点(End)分别有2块石头,S到E的距离就是L. 河中有n块石头,每块石头到S都 ...
- poj 3258 River Hopscotch 二分
/** 大意:给定n个点,删除其中的m个点,其中两点之间距离最小的最大值 思路: 二分最小值的最大值---〉t,若有距离小于t,则可以将前面的节点删除:若节点大于t,则继续往下查看 若删除的节点大于m ...
- POJ 3258 River Hopscotch 二分枚举
题目:http://poj.org/problem?id=3258 又A一道,睡觉去了.. #include <stdio.h> #include <algorithm> ]; ...
随机推荐
- wampserver环境下,apache本地下设置多个域名
Apache在安装之后默认只是指向一个站点,即127.0.0.1,如果要进行多站点的配置,需要更改一些配置. 步骤.方法: 1,)让Apache在启动时能加载虚拟主机模块. 打开Apache安装目录下 ...
- Custom IFormatProvider
The following example shows how to write a custom IFormatProvider which you can use in methodString. ...
- PostgreSQL与RPM
如何查看使用PostgreSQL的RPM包安装后的文件目录及相关路径(PostgreSQLRPM的spec文件已经帮我们创建好了postgres用户及postgres组). 查看RPM文档信息:/us ...
- poj 1475 || zoj 249 Pushing Boxes
http://poj.org/problem?id=1475 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=249 Pushin ...
- BroadCast Receive 生命周期
BroadCastReceiver 简介 BroadCastReceiver 源码位于: framework/base/core/java/android.content.BroadcastRecei ...
- C++之路进阶——hdu2222(Keywords Search)
/*Keywords Search Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- linux中的一个看图的软件
毕竟才是初入linux,很多工具,先要要求有个用着,之后再要求小巧强大好用. 看图软件,不喜欢kde或者是gnome这种庞大的桌面环境,也就不喜欢一些跟特定桌面环境沾边的软件(总觉得用软件必须要用特定 ...
- Ubentu搭建nfs服务器
搭建nfs服务 功能:完成在线调试程序,远程挂载,在线调试 NFS(Network FileSystem,网络文件系统)是由SUN公司发展,并于1984年推出的技术,用于不同机器,不同操作 ...
- 【linux】xx is not in the sudoers file 解决办法
原帖地址:http://blog.sina.com.cn/s/blog_4ef045ab0100j59t.html 我用的是redhat5.4,在一般用户下执行sudo命令提示llhtiger is ...
- yii2购物车实现
1.商品列表中点击加入购物车,则跳转到购物车列表,效果如图所示: 视图代码goods/list.php中.代码如下: <?php echo Html::a('加入购物车',['cart','id ...