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> ]; ...
随机推荐
- php基础语法学习汇总
常量学习: <?php # function demo function sum($x,$y){ $z=$x+$y; return $z; } echo sum(1,2); #define de ...
- 我写了本破书-swift语言实战晋级
本书是一本介绍Swift实战的实用图书,旨在帮有一定编程基础的童鞋能够快速上手Swift. 本书的结构是先讲解了Swift语言的精要,没有基础的童鞋可以学习,有基础的童鞋可以当做复习. 接着讲解如何用 ...
- Winform 基本属性
WinForm--- 客户端应用程序 - 是需要安装在用户电脑上才可以使用的程序特点:不需要联网也可以打开使用部分功能但是现在的情况是许多功能依然需要互联网的支持 代码部分在用户电脑上执行 WinFo ...
- 趣谈PHP 多态
多态性是指相同的操作或函数.过程可作用于多种类型的对象上并获得不同的结果.不同的对象,收到同一消息将可以产生不同的结果,这种现象称为多态性. 多态性允许每个对象以适合自身的方式去响应共同的消息.多态性 ...
- yii遍历行下的每列数据(小1月考)
效果图: 控制器(1种): //显示列表 public function actionList() { //实例化对象 $model= new Qiu(); ...
- snmp getTable demo :iftable ipAddresstable
package org.huangxf.snmp.test; import java.io.IOException; import java.util.List; import org.snmp4j. ...
- paper 82:边缘检测的各种微分算子比较(Sobel,Robert,Prewitt,Laplacian,Canny)
不同图像灰度不同,边界处一般会有明显的边缘,利用此特征可以分割图像.需要说明的是:边缘和物体间的边界并不等同,边缘指的是图像中像素的值有突变的地方,而物体间的边界指的是现实场景中的存在于物体之间的边界 ...
- 14---Net基础加强
更新中,敬请期待............ 复习-匿名类型 Xml介绍
- 夺命雷公狗ThinkPHP项目之----企业网站17之网站配置页的添加
为了网站可以智能一点,所以我们开始来写一个网站配置的功能.. 所以我来写他的数据表: 先来完成他的添加功能,页面效果如下所示: lists.html代码如下所示: <!doctype html& ...
- 【crunch bang】中文美化
原文连接:http://edyfox.codecarver.org/html/debian_testing_chinese.html 中文字体美化是个很讨厌的事情,无数初学者在这里面浪费了无数时间,做 ...