首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >【POJ】3258 - River Hopscotch(二分)

【POJ】3258 - River Hopscotch(二分)

作者头像
FishWang
发布2025-08-26 19:49:57
发布2025-08-26 19:49:57
8000
代码可运行
举报
运行总次数:0
代码可运行

点击打开题目

River Hopscotch

Time Limit: 2000MS

Memory Limit: 65536K

Total Submissions: 11157

Accepted: 4787

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 ≤ MN).

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

代码语言:javascript
代码运行次数:0
运行
复制
25 5 2
2
14
11
21
17

Sample Output

代码语言:javascript
代码运行次数:0
运行
复制
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

USACO 2006 December Silver

题有点长。题意大概为:有一个宽为 w 的河,河中有 n 块石头,最多可以移走 k 块。求他的小牛需要蹦的最小距离的最大值。

代码如下:

代码语言:javascript
代码运行次数:0
运行
复制
#include <cstdio>
#include <algorithm>
using namespace std;
int w,n,k;
int num[50000+11];
bool check(int x)
{
	int pos,t;
	int rec = k;
	pos = lower_bound (num , num + n , x) - num;
	rec = rec - pos;
	if (rec < 0)
		return false;
	else if (pos == n)
		return true;
	while (rec >= 0)
	{
		t = lower_bound (num , num + n , num[pos] + x) - num;
		rec = rec - (t - pos - 1);
		if (rec < 0)
			return false;
		else if (t == n)
			return true;
		pos = t;
	}
}
int main()
{
	int l,r,mid;
	while (~scanf ("%d %d %d",&w,&n,&k))
	{
		num[0] = w;
		for (int i = 1 ; i <= n ; i++)
			scanf ("%d",&num[i]);
		n++;
		sort (num , num + n);
		l = 1;
		r = num[n-1];
		while (r >= l)
		{
			mid = (l + r) >> 1;
			if (check (mid))
				l = mid + 1;
			else
				r = mid - 1;
		}
//		printf ("%d\n",l);		//这道题的情况特殊,结果并不是l
		printf ("%d\n",l-1);
	}
	return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2025-08-26,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档