8.17--练习赛B题--River Hopscotch(二分)
来源:互联网 发布:客户管理系统源码 编辑:程序博客网 时间:2024/06/06 02:31
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.
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.
25 5 2214112117
4
题意:跟以前讲的一个青蛙跳石头的题一样。题意就是有n块石头,给出间隔,然后取出m块石头,问其间隔最小的最大值是多少。
思路:二分求就好了
源代码:
#include <iostream>#include <cstring>#include <algorithm>#include <stdio.h>#include <queue>#include <iomanip>#include <string>using namespace std;long long dis[10000000];long long l,n,m;int main(){ scanf("%lld%lld%lld",&l,&n,&m); dis[0] = 0; for (int i = 1; i <= n; i++) scanf("%lld",&dis[i]); sort(dis,dis+n+1); long long lp = 0; long long rp = l; long long mid; long long MIN = rp; while (lp <= rp) { mid = (lp + rp) / 2; long long sum = 0; long long d = 0; for (int i = 1; i <= n; i++) { if (dis[i] - dis[d] <= mid) sum++; else d = i; } if (sum > m) { MIN = min(MIN,mid); rp = mid - 1; } else lp = mid + 1; } printf("%lld\n",MIN); return 0;}
- 8.17--练习赛B题--River Hopscotch(二分)
- River Hopscotch(二分)
- poj3258--River Hopscotch(二分)
- River Hopscotch(二分最大值)
- POJ3258 River Hopscotch(二分)
- POJ3528:River Hopscotch(二分)
- poj River Hopscotch 3258 (二分)好题
- TOJ 2836.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 (二分经典)
- Struts2 方法动态调用,验证表签,xml配置Action
- hdu 6140
- 51 nod 1435 位数阶乘
- 剑指Offer_面试题33_把数组排成最小的数
- Android Binder机制浅析(一)
- 8.17--练习赛B题--River Hopscotch(二分)
- ARM学习笔记三
- IO流
- Python3爬虫代理服务器与cookie的使用
- 几种web服务器端推送技术的简单介绍
- 半平面交
- SQL的多表查询和子查询
- java代码优化
- Fiddler 查看请求的服务器类型和IP