POJ_3258_River_Hopscotch_[NOIP2015]_(二分,最大化最小值)
描述
http://poj.org/problem?id=3258
给出起点和终点之间的距离L,中间有n个石子,给出第i个石子与起点之间的距离d[i],现在要去掉m个石子(不包括起终点),求距离最近的两个石子(包括起终点)之间距离的最大值.
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 10841 | Accepted: 4654 |
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
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
Sample Input
25 5 2
2
14
11
21
17
Sample Output
4
Hint
Source
分析
二分.
同 POJ 2456 , 但有一点不同:start与end位置是已经确定好的,只需要在中间n个石子中确定n-m个即可.第一个石子与a[0]即start位置比较,结束之后还要再比较a[n+1]-a[last]>=x是否成立.(也是注意点1)
#include<cstdio>
#include<algorithm>
using std :: sort; const int maxn=;
int n,l,m;
int a[maxn]; void init()
{
scanf("%d%d%d",&l,&n,&m);
for(int i=;i<=n;i++) scanf("%d",&a[i]);
sort(a+,a+n+);
a[n+]=l;
} bool C(int x)
{
int last=;
for(int i=;i<=n-m;i++)
{
int now=last+;
while(now<=n&&(a[now]-a[last])<x) now++;
if(now>n) return false;
last=now;
}
if(a[n+]-a[last]<x) return false;
return true;
} int bsearch(int x,int y)
{
while(x<y)
{
int m=x+(y-x+)/;
if(C(m)) x=m;
else y=m-;
}
return x;
} void solve()
{
int INF=l/(n+-m);//共n+1-m个线段,最短的线段最多是l/(n+1-m)
int ans=bsearch(,INF);
printf("%d\n",ans);
} int main()
{
freopen("river.in","r",stdin);
freopen("river.out","w",stdout);
init();
solve();
fclose(stdin);
fclose(stdout);
return ;
}
注意:
1.如上所述.
2.输入数据是无序的,需先用快排进行排序.
POJ_3258_River_Hopscotch_[NOIP2015]_(二分,最大化最小值)的更多相关文章
- POJ_2456_Agressive_cows_(二分,最大化最小值)
描述 http://poj.org/problem?id=2456 有n个小屋,线性排列在不同位置,m头牛,每头牛占据一个小屋,求最近的两头牛之间距离的最大值. Aggressive cows Tim ...
- River Hopscotch(二分最大化最小值)
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9923 Accepted: 4252 D ...
- POJ3258 River Hopscotch(二分最大化最小值)
题目链接:http://poj.org/problem?id=3258 题意:给n个石头,起点和终点也是两个石头,去掉这石头中的m个,使得石头间距的最小值最大. 思路:二分石头间的最短距离,每次贪心地 ...
- CodeForces 689C Mike and Chocolate Thieves (二分最大化最小值)
题目并不难,就是比赛的时候没敢去二分,也算是一个告诫,应该敢于思考…… #include<stdio.h> #include<iostream> using namespace ...
- poj3104 Drying(二分最大化最小值 好题)
https://vjudge.net/problem/POJ-3104 一开始思路不对,一直在想怎么贪心,或者套优先队列.. 其实是用二分法.感觉二分法求最值很常用啊,稍微有点思路的二分就是先推出公式 ...
- POJ - 2456 Aggressive cows 二分 最大化最小值
Aggressive cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18099 Accepted: 8619 ...
- poj3045 Cow Acrobats(二分最大化最小值)
https://vjudge.net/problem/POJ-3045 读题后提取到一点:例如对最底层的牛来说,它的崩溃风险=所有牛的重量-(底层牛的w+s),则w+s越大,越在底层. 注意范围lb= ...
- POJ3285 River Hopscotch(最大化最小值之二分查找)
POJ3285 River Hopscotch 此题是大白P142页(即POJ2456)的一个变形题,典型的最大化最小值问题. C(x)表示要求的最小距离为X时,此时需要删除的石子.二分枚举X,直到找 ...
- poj 2456 Aggressive cows && nyoj 疯牛 最大化最小值 二分
poj 2456 Aggressive cows && nyoj 疯牛 最大化最小值 二分 题目链接: nyoj : http://acm.nyist.net/JudgeOnline/ ...
随机推荐
- Gulp实战(二)
一.配置环境 1.基于NodeJs安装Git,npm,gulp 2.安装各类插件 3.参考文档 http://www.tuicool.com/articles/UbaqyyJ http://www.t ...
- 【制作镜像Win*】特殊配置
下载disk.config: wget http://10.254.3.75/images/configdrive/disk.config 修改libvirt.xml,更换cdrom为disk.con ...
- KMP(匹配)
Description 一块花布条,里面有些图案,另有一块直接可用的小饰条,里面也有一些图案.对于给定的花布条和小饰条,计算一下能从花布条中尽可能剪出几块小饰条来呢? Input 输入中含有一些数据, ...
- C++ 遇见的一些函数
1.位与(&)操作,计算十进制数中的为"1"的位数 int cnt_one(int k) { ; //保存位为"1"的数量 while (k) { k ...
- InstallShield 版本转换
InstallShield : 如何用低版本 打开高版本的工程 InstallShield 每个版本都有对应的版本号SchemaVersion,如下所示 InstallShield Versi ...
- 抽象工厂(Abstract Factory)模式
一.抽象工厂(Abstract Factory)模式 抽象工厂模式是所有形态的工厂模式中最为抽象和最具一般性的一种形态. 为了方便引进抽象工厂模式,引进一个新概念:产品族(Product Family ...
- 在Mac OS X中搭建STM32开发环境(1)
本文原创于http://www.cnblogs.com/humaoxiao,非法转载者请自重! 本文方法必须好用!绝不坑爹!看了N多英文资料才搞明白的,适用于STM32F4DISCOVERY评估板,带 ...
- Windows phone 8 安装在 VMWare上错误的各种解决方案
http://windowsasusual.blogspot.jp/2013/01/how-to-launch-windows-phone-8-emulator.html Hardware requi ...
- 网站重构-你了解AJAX吗?
AJAX是时下最流行的一种WEB端开发技术,而你真正了解它的一些特性吗?--IT北北报 XMLHTTPRequest(XHR)是目前最常用的技术,它允许异步接收和发送数据,所有的主流浏览器都对它有不错 ...
- CentOS 6.6x64下编译gcc-4.7.4
最近使用老版本的gcc发现一些问题,于是想尝试升级. 看了一些教程之后进行尝试,发现各类教程均会有一些小问题,于是在此记录一下本人的过程. 编译过程中参考的文章有如下几篇,在此表示感谢: http:/ ...