POj 3258 River Hopscotch 二分搜索 最大化最小值
来源:互联网 发布:i5处理器编程够用么 编辑:程序博客网 时间:2024/06/05 18:00
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 2214112117
Sample Output
4
Hint
Source
#include<cstdio>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
using namespace std;
#define MM(a) memset(a,0,sizeof(a))
typedef long long LL;
typedef unsigned long long ULL;
const int mod = 1000000007;
const double eps = 1e-10;
const int inf = 0x3f3f3f3f;
int x[50005],L,n,m;;
int ok(int d)
{
int cnt=0,last=0;
for(int i=1;i<=n;i++)
if(x[i]-last<d)
{
cnt++;
if(cnt>m)
return 0;
}
else
last=x[i];
return 1;
}
int main()
{
while(~scanf("%d %d %d",&L,&n,&m))
{
for(int i=1;i<=n;i++)
scanf("%d",&x[i]);
n++;x[n]=L;x[0]=0;
sort(x+1,x+n+1);
int mid,l=0,r=x[n];
while(l<r)
{
mid=l+(r-l+1)/2;
if(ok(mid))
l=mid;
else
r=mid-1;
}
printf("%d\n",r);
}
return 0;
}
int mid,l=0,r=x[n]+1;
while(r-l>1)
{
mid=(l+r)/2;
if(ok(mid))
l=mid;
else
r=mid;
}
printf("%d\n",l);
- poj 3258 River Hopscotch (二分搜索---最大化最小值)
- POJ - 3258 River Hopscotch(二分搜索:最大化最小值)
- POJ 3258 River Hopscotch(二分搜索,最大化最小值)
- POj 3258 River Hopscotch 二分搜索 最大化最小值
- POJ 3258 River Hopscotch (二分,最大化最小值)
- POJ 3258 River Hopscotch【二分:最大化最小值】
- [ACM] POJ 3258 River Hopscotch (二分,最大化最小值)
- [ACM] POJ 3258 River Hopscotch (二分,最大化最小值)
- poj 3258 River Hopscotch 【二分查找(最大化最小值)】
- POJ题目3258 River Hopscotch(二分最小值最大化)
- POJ 3258 River Hopscotch(贪心+二分查找 最大化最小值)
- POJ 3258 River Hopscotch (最大化最小值)二分
- poj 3258 River Hopscotch(二分最大化最小值)
- poj 3258 River Hopscotch (最小值最大化 二分+贪心)
- 【贪心专题】POJ 3258 River Hopscotch (最大化最小值 贪心+二分搜索)
- POJ 3258 River Hopscotch(最大化最小值)
- poj--3258 River Hopscotch(最大化最小值)
- POJ 3258 River Hopscotch (二分 + 最大化最小值 + 模拟双向链表)
- poj 3259 Wormholes 最短路bellman 题意转化很重要
- Spring配置之RMI
- poj 2456 Aggressive cows 整数二分写法 模板题
- poj 3104 Drying 二分搜索--查找最小yes值
- poj 3111 K Best 二分搜索 最大化平均值
- POj 3258 River Hopscotch 二分搜索 最大化最小值
- poj 2674 Linear world 弹性碰撞 升级的蚂蚁
- poj 2785 4 Values whose Sum is 0
- Codeforces Round #324 (Div. 2) A. Olesya and Rodion 构造数字 思维题
- Codeforces Round #324 (Div. 2) B. Kolya and Tanya 思维题 数论
- Poj 3977 Subset 折半枚举 超大背包
- poj 2549 Sumsets 折半枚举
- poj 3276 Face The Right Way 挑战150 反转
- poj 3279 Fliptile 反转