A - River Hopscotch
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).
用二分,找到是否符合条件的间距
There is a literal backtick (`) here.
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define pb push_back
#include<vector>
typedef long long ll;
typedef long double ld;
const ll MOD=1e9+7;
using namespace std;
ll a[50005];
ll l,n,num;
bool judge(ll mid)
{
int bits=0;
for(int i=0;i<n;i++)
{
int ans=0;
for(int j=1;j<=n-i;j++)
{
if(a[i+j]-a[i]<mid)
{
ans++;
bits++;
}else
break;
}
i+=ans;
if(bits>num)
{
return true;
}
}
return false;
}
int main()
{
a[0]=0;
cin>>l>>n>>num;
for(int i=1;i<=n;i++)
cin>>a[i];
a[n+1]=l;
n++;
sort(a,a+n+1);
ll left=0,right=l,mid=(left+right)/2;
while(right-left>1)
{
if(judge(mid))
{
right=mid;
}else
{
left=mid;
}
mid=(left+right)/2;
}
while(!judge(mid))mid++;
cout<<mid-1;
}
A - River Hopscotch的更多相关文章
- POJ 3258 River Hopscotch
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 11031 Accepted: 4737 ...
- River Hopscotch(二分POJ3258)
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9263 Accepted: 3994 Descr ...
- POJ 3258 River Hopscotch (binarysearch)
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5193 Accepted: 2260 Descr ...
- POJ3285 River Hopscotch(最大化最小值之二分查找)
POJ3285 River Hopscotch 此题是大白P142页(即POJ2456)的一个变形题,典型的最大化最小值问题. C(x)表示要求的最小距离为X时,此时需要删除的石子.二分枚举X,直到找 ...
- River Hopscotch(二分最大化最小值)
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9923 Accepted: 4252 D ...
- POJ--3258 River Hopscotch (最小值最大化C++)
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 15273 Accepted: 6465 ...
- POJ 3258 River Hopscotch(二分答案)
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 21939 Accepted: 9081 Desc ...
- bzoj1650 / P2855 [USACO06DEC]河跳房子River Hopscotch / P2678 (noip2015)跳石头
P2855 [USACO06DEC]河跳房子River Hopscotch 二分+贪心 每次二分最小长度,蓝后检查需要去掉的石子数是否超过限制. #include<iostream> #i ...
- River Hopscotch
River Hopscotch http://poj.org/problem?id=3258 Time Limit: 2000MS Memory Limit: 65536K Total Submi ...
- POJ3258 River Hopscotch 2017-05-11 17:58 36人阅读 评论(0) 收藏
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13598 Accepted: 5791 ...
随机推荐
- !HDU 1574 RP-dp-(重点在状态确定)
题意:有n件事.每件事若发生有两种情况.添加RP为a,可是收益会降低c:降低R为a,收益会添加c. 每件事可以发生的前提是小于等于或者大于等于门限值b.求最大收益. 分析:这题我没找到状态,所以就不会 ...
- ubuntu 定时执行任务at
安装方法: apt-get install at 使用方法: 添加 at 11:13 warning: commands will be executed using /bin/sh at> & ...
- [转]POJ3624 Charm Bracelet(典型01背包问题)
来源:https://www.cnblogs.com/jinglecjy/p/5674796.html 题目链接:http://bailian.openjudge.cn/practice/4131/ ...
- 保持APP后台NSTimer运行
[[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:nil]; self.timer = [NSTi ...
- Variable used in lambda expression should be final or effectively final
Lambda与匿名内部类在访问外部变量时,都不允许有修改变量的倾向,即若: final double a = 3.141592; double b = 3.141592; DoubleUnaryOpe ...
- 【Java】数组不能通过toString方法转为字符串
java里,所有的类,不管是java库里面的类,或者是你自己创建的类,全部是从object这个类继承的.object里有一个方法就是toString(),那么所有的类创建的时候,都有一个toStrin ...
- C#中回滚TransactionScope的使用方法和原理
TransactionScope只要一个操作失败,它会自动回滚,Complete表示事务完成 实事上,一个错误的理解就是Complete()方法是提交事务的,这是错误的,事实上,它的作用的表示本事 ...
- 如何在servlet刚启动时候获取服务器根目录?
public class InitServlet extends HttpServlet{ public static String root; @Override public void init( ...
- Vue 温故而知新 props如何双向属性绑定
传送门:https://cn.vuejs.org/v2/guide/components-custom-events.html https://segmentfault.com/q/101000001 ...
- Appium 输入 & 符号,实际输入&-
2018-10-11 12:27:12:178 - [debug] [MJSONWP] Calling AppiumDriver.setValue() with args: [["& ...