POJ3258 River Hopscotch 2017-05-11 17:58 36人阅读 评论(0) 收藏
|
River Hopscotch
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 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 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 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).
Source |
——————————————————————————————————
题目的意思是给出n个数,取走m个要求两两之间(以及和岸的)最小值最大是多少?
思路:二分最小距离+验证
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define inf 0x3f3f3f3f
#define LL long long int a[100005];
int n,m,mx;
bool ok(int x)
{
int cnt=0;
int sum=0;
for(int i=1;i<n;i++)
{
sum+=a[i]-a[i-1];
if(sum<x)
cnt++;
else
sum=0;
}
if(cnt<=m)
return 1;
return 0; } int main()
{ while(~scanf("%d%d%d",&mx,&n,&m))
{
a[0]=0,a[n+1]=mx;
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
n+=2;
sort(a,a+n);
int l=0,r=1000000000;
int ans;
while(l<=r)
{
int mid=(l+r)/2;
if(ok(mid))
{
l=mid+1;
ans=mid;
}
else
{
r=mid-1;
}
}
printf("%d\n",ans);
}
return 0;
}
POJ3258 River Hopscotch 2017-05-11 17:58 36人阅读 评论(0) 收藏的更多相关文章
- hash值的计算与转换 分类: ACM TYPE 2015-05-07 17:49 36人阅读 评论(0) 收藏
#include <bits/stdc++.h> using namespace std; const int MAXN = 100; const int X = 3; long long ...
- Java中的日期操作 分类: B1_JAVA 2015-02-16 17:55 6014人阅读 评论(0) 收藏
在日志中常用的记录当前时间及程序运行时长的方法: public void inject(Path urlDir) throws Exception { SimpleDateFormat sdf = n ...
- strace使用详解(转) 分类: shell ubuntu 2014-11-27 17:48 134人阅读 评论(0) 收藏
(一) strace 命令 用途:打印 STREAMS 跟踪消息. 语法:strace [ mid sid level ] ... 描述:没有参数的 strace 命令将所有的驱动程序和模块中的 ...
- hdu 1057 (simulation, use sentinel to avoid boudary testing, use swap trick to avoid extra copy.) 分类: hdoj 2015-06-19 11:58 25人阅读 评论(0) 收藏
use sentinel to avoid boudary testing, use swap trick to avoid extra copy. original version #include ...
- Design T-Shirt 分类: HDU 2015-06-26 11:58 7人阅读 评论(0) 收藏
Design T-Shirt Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- UIAlertController高级之嵌入其他控件 分类: ios技术 2015-02-02 11:58 96人阅读 评论(0) 收藏
在编码过程中,我们经常遇到需要这样一个效果,就是弹出框的嵌套; 举个最简单的例子,比如你要选择时间,必然需要一个时间选择器DatePicker.但是这个选择器又是在你点击某按钮时弹出,弹出方式最常见的 ...
- Codeforces735B Urbanization 2016-12-13 11:58 114人阅读 评论(0) 收藏
B. Urbanization time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- StatusStrip 分类: C# 2015-07-23 11:58 2人阅读 评论(0) 收藏
通过StatusStrip显示窗体状态栏 同时将状态栏分成三部分 居左边显示相关文字信息 中间空白显示 居右边显示时间信息 1.创建窗体及添加StatusStrip 默认StatusStrip名称 ...
- APP被苹果APPStore拒绝的各种原因 分类: ios相关 app相关 2015-06-25 17:27 200人阅读 评论(0) 收藏
APP被苹果APPStore拒绝的各种原因 1.程序有重大bug,程序不能启动,或者中途退出. 2.绕过苹果的付费渠道,我们之前游戏里的用兑换码兑换金币. 3.游戏里有实物奖励的话,一定要说清楚,奖励 ...
随机推荐
- 安装Anaconda以及jupyter的使用
1)下载https://www.anaconda.com/download/ 2)安装 3)终端查看(Anaconda Prompt) 4)升级所有的包 初次安装下的软件包版本一般都比较老旧,因此提前 ...
- 本地Maven库添加SQLServer2012 sqljdbc4.jar
最近又开始搞Java项目了,学习下maven用法(ant时代真的过去了啊?) 选了个国内的小框架来做,有个小需求,客户需要用牛逼哄哄的SQLServer,新版的比如SQLServer2012的sqlj ...
- 真验货客户尾缀sql
'; --select * from TB_ADDBOMWG_LOG; --SELECT * FROM TB_MAN_ROUTING_QM; SELECT * FROM IN_ITEM WHERE I ...
- Android模拟器内安装应用
一.通过apk安装器安装应用 1.下载apk安装器(网上随便搜一个就可以) 2.下载要测试的应用的apk,我这里下载的是微信的apk 3.打开apk安装器,点击右上角的Devices选择要安装到的设备 ...
- 第八章 高级搜索树 (a1)伸展树:逐层伸展
- Tomb Raider(暴力模拟)
Tomb Raider https://hihocoder.com/problemset/problem/1829?sid=1394836 时间限制:1000ms 单点时限:1000ms 内存限制:2 ...
- .NET中CORS跨域访问WebApi
我这里只写基本用法以作记录,具体为什么看下面的文章: http://www.cnblogs.com/landeanfen/p/5177176.html http://www.cnblogs.com/m ...
- Go开发之VScode安装
1.找到官网 https://code.visualstudio.com/ 2根据自己机器环境下载 3.下载vscode地址,macos版本 https://vscode.cdn.azure.cn/s ...
- script标签的type="test/html"时
们可以在<script>片断中定义一个被JS调用的代码,但代码又不在页面上显示,这时,我们可以使用下面的方法: 1 <script id="commentTemplate& ...
- 运行 .jar dos 命令
命令行进入 jar 所在文件夹 执行 java -jar a.jar;