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> ]; ...
随机推荐
- 如何使用Jlink
下载程序: 1. 连上Jlink的USB到PC上.连接JTAG到GT2440开发板上,选择从Nor Flash 启动. 2. 板子上电后,启动J-Flash ARM .File -> New P ...
- C++之路进阶——bzoj2152(聪聪可可)
F.A.Qs Home Discuss ProblemSet Status Ranklist Contest ModifyUser hyxzc Logout 捐赠本站 Notice:由于本OJ建立在 ...
- const修饰
const int A() //const // ====>int A(const this) { //观点1:const是修饰a,但是通过测试,我们发现,b++也不能编译通过 //这说明:co ...
- php 警告
php.ini error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT error_log = /var/log/php-fpm/php ...
- spark读取hdfs数据本地性异常
在分布式计算中,为了提高计算速度,数据本地性是其中重要的一环. 不过有时候它同样也会带来一些问题. 一.问题描述 在分布式计算中,大多数情况下要做到移动计算而非移动数据,所以数据本地性尤其重要,因此我 ...
- xla_events
LOOKUP_TYPE LANGUAGE LOOKUP_CODE MEANING DESCRIPTION XLA_EVENT_PROCESS_STATUS US D Draft Draft XLA_E ...
- 夺命雷公狗---DEDECMS----21dedecms按照地区取出电影内容
我们现在要做的就是: 这些电影都是要按照地区来取出才可以的,但是我们arclist标签里面有没有按照条件来查找的地方,我们只好换套路了,要不然条条大路都不通,,,, 我们先来构造一条语句: 他这个标签 ...
- 机器学习中的范数规则化之(一)L0、L1与L2范数(转)
http://blog.csdn.net/zouxy09/article/details/24971995 机器学习中的范数规则化之(一)L0.L1与L2范数 zouxy09@qq.com http: ...
- [slim] Slim - Faster, lightweight, a enginer for Ruby
URL: http://slim-lang.com/ Example: doctype html html head title Slim Examples meta name="keywo ...
- javascript中字符串格式json如何转化成json对象
什么是JSON JSON(JavaScript Object Notation)是一种优美的JavaScript对象创建方法.JSON也是一种轻量级数据交换格式.JSON非常易于人阅读与编写,同时利于 ...