POJ3258 River Hopscotch

  地址

  别人的代码,自己边界总是控制不好,还不知道哪里错了!思维!这种问题代码越简洁反而越不容易错吧。。

 1     #include<stdio.h>
 2     #include<algorithm>
 3     typedef long long ll;
 4     using namespace std;
 5     ll n,m,L,a[100010];
 6     bool bi(ll x){
 7         ll i,cnt=0,now=0;
 8         for(i=1;i<=n;i++){
 9             if(a[i]-a[now]<=x)cnt++;
10             else    now=i;
11         }
12         if(L-a[now]<x)return 0;
13         return cnt<=m;
14     }
15     int main(){
16         ll i,l,r,mi;
17         while(~scanf("%lld%lld%lld",&L,&n,&m)){
18             l=0;r=L;
19             for(i=1;i<=n;i++)
20                 scanf("%lld",&a[i]),
21                 r+=a[i];
22             sort(a,a+n+1);
23             while(l<r){
24                 mi=l+r>>1;
25                 if(bi(mi))l=mi+1;
26                 else      r=mi;
27             }
28             printf("%lld\n",r);
29         }
30         return 0;
31     }  

时间: 2024-08-07 00:16:04

POJ3258 River Hopscotch的相关文章

POJ3258 River Hopscotch —— 二分

题目链接:http://poj.org/problem?id=3258 River Hopscotch Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 15753   Accepted: 6649 Description Every year the cows hold an event featuring a peculiar version of hopscotch that involves carefully ju

POJ3258:River Hopscotch(二分)

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 th

bzoj1650[Usaco2006 Dec]River Hopscotch 跳石子*

bzoj1650[Usaco2006 Dec]River Hopscotch 跳石子 题意: 数轴上有n个石子,第i个石头的坐标为Di,现在要从0跳到L,每次跳都从一个石子跳到相邻的下一个石子.现在问移走这M个石子后,相邻两个石子及0到最前一个石子及最后一个石子到L距离的最小值的最大值是多少.n≤50000 题解: 为什么有NOIP2015即视感~二分距离最小值,然后如果当前石子和上一个石子相差小于二分值就将这个石子移走,如果位置L与上一个石子相差小于二分值,此时若还没有移满M个且有没移走的石子

POJ 3258 River Hopscotch 经典二分

点击打开链接 River Hopscotch Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6189   Accepted: 2683 Description Every year the cows hold an event featuring a peculiar version of hopscotch that involves carefully jumping from rock to rock in a r

POJ 3258 River Hopscotch

River Hopscotch Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11031   Accepted: 4737 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.

POJ3285 River Hopscotch(最大化最小值之二分查找)

POJ3285 River Hopscotch 此题是大白P142页(即POJ2456)的一个变形题,典型的最大化最小值问题. C(x)表示要求的最小距离为X时,此时需要删除的石子.二分枚举X,直到找到最大的X,由于c(x)=m时满足题意,所以最后输出的是ub-1或者lb(lb==ub-1 注意相邻距离小于x的要删除(此处不是小于等于),对于相邻的距离小于x的两个石子,当删除其中一个后,又会产生其他的相邻的石子,直接计数不好计数,不妨用两个标记last,cur,其中last表示上一个石子,cur

[ACM] POJ 3258 River Hopscotch (二分,最大化最小值)

River Hopscotch Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6697   Accepted: 2893 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. T

POJ 3258 River Hopscotch 二分答案

River Hopscotch Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6193   Accepted: 2685 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. T

二分搜索 POJ 3258 River Hopscotch

题目传送门 1 /* 2 二分:搜索距离,判断时距离小于d的石头拿掉 3 */ 4 #include <cstdio> 5 #include <algorithm> 6 #include <cstring> 7 #include <cmath> 8 using namespace std; 9 10 typedef long long ll; 11 const int MAXN = 5e4 + 10; 12 const int INF = 0x3f3f3f3