River Hopscotch(二分)
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 5473 | Accepted: 2379 |
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 Mrocks (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 ofM 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 输入L,N,M;L表示终点离起点的距离,从起点到终点有N块石头(不包含起点和终点),要求移除M块石头后,使得那时的最短距离尽可能的大,并输出这个距离;
类似于poj3273;
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std; const int N = ;
int l,n,m;
int rock[N+];
int low,high,mid; bool judge(int mid)
{
int sum = ;
int group = ;
for(int i = ; i <= n+; i++)
{
if(sum + (rock[i]-rock[i-]) <= mid)
{
sum += rock[i]-rock[i-];
group++;
}
else
{
sum = ;
}
}
if(group > m)
return false;
return true;
} int main()
{
scanf("%d %d %d",&l,&n,&m);
rock[] = ;
rock[n+] = l;
low = l;
high = l;
for(int i = ; i <= n+; i++)
{
if(i <= n)
scanf("%d",&rock[i]);
if(low > rock[i]-rock[i-])
low = rock[i]-rock[i-];
}
sort(rock,rock+(n+)); while(low <= high)
{
mid = (low+high)/;
if(!judge(mid))
high = mid-;
else low = mid+;
}
printf("%d\n",low);
return ;
}
River Hopscotch(二分)的更多相关文章
- River Hopscotch(二分POJ3258)
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9263 Accepted: 3994 Descr ...
- 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 ...
- 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: 9326 Accepted: 4016 D ...
- G - River Hopscotch(二分)
Every year the cows hold an event featuring a peculiar version of hopscotch that involves carefully ...
- 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> ]; ...
随机推荐
- iOS 手机淘宝加入购物车动画分析
1.最终效果 仿淘宝动画 2.核心代码 _cartAnimView=[[UIImageView alloc] initWithFrame:CGRectMake(_propView.frame.size ...
- HTML简单介绍及常见元素
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- Customizing the Test Runner
There are several situations where you want to customize Robolectric's test runner to perform some o ...
- C#语法糖之开篇
本人虽然大学不是学的计算机但是对于IT行业的热爱,依然决然进军IT行业了,自从踏进这个行业到现在也已经3年多了,从去年开发通过网上 了解博客园后深深的爱上这儿了,这里有很多牛人,通过拜读他们的代码,让 ...
- 枚举,Enum,常规使用demo记录
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Mv ...
- apk文件解析,学习笔记
Android 应用程序包文件 (APK) 是一种Android操作系统上的应用程序安装文件格式,其英文全称为 “application package file” . 如果懂得使用反编译工具,可以下 ...
- [笔记]dynamic gamma correction
2014-03-17 14:37:04 周一 在设计过程中参考论文<一种改进的视频画质增强算法及VLSI设计>电子学报 在YUV色彩空间对输入图像的信息进行判断分类和对比度调整,然后对调 ...
- 如何管理你的 Javascript 代码
今天不聊技术的问题,咱们来聊聊在前端开发中如何管理好自己的 Javascript 代码.首先,咱们先来说说一般都有哪些管理方式?我相信 seajs . requirejs 对于前端开发者而言都不陌 ...
- iOS NSData简单解析
iOS 基本数据类型之NSData 1 nsdata 作用: 用于存储二进制的数据类型 nadat类提供一种简单的方式,它用来设置缓存区.将文件的内容读入到缓存区.或者将缓存区中的内容写到一个文件. ...
- ubuntu系统安装的MySql数据库,远程不能访问的几种可能问题
安装MySQL数据库后一般会遇到远程计算机不能连接的问题,具体问题需要我们排查.可能一:MySql数据库是否提供了外部访问的用户以及权限?可能二:MySql的配置文件是否只绑定了本机ip(ubuntu ...