poj 3258River Hopscotch

题意:一条长l的河,0和l各有一个石头,中间有n个石头,从中间n个石头中去掉m个石头,求所有剩余石头之间距离的最小的最大值

分析:二分

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=1e5+5;
int c[maxn];
int lo,n,m;

bool judge(int x){
    int t=0,last=0;
    for(int i=0;i<n;i++)
      if(c[i]-last>=x){
          t++;
          last=c[i];
          if(t==n-m)
            break;
      }
    return (t==(n-m))&&(lo-last>=x);
}

int main(){
    while(~scanf("%d%d%d",&lo,&n,&m)){
        for(int i=0;i<n;i++)
          scanf("%d",c+i);
        sort(c,c+n);
        int l=0,r=lo;
        while(r-l>0){
            int mid=l+(r-l+1)/2;
            if(judge(mid))
              l=mid;
            else
              r=mid-1;
        }
        printf("%d\n",l);
    }
    return 0;
}

时间: 2024-10-29 19:10:33

poj 3258River Hopscotch的相关文章

POJ 3258- River Hopscotch(二分求最小值最大)

River Hopscotch Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 3258 Appoint description:  System Crawler  (2015-05-27) Description Every year the cows hold an event featuring a peculiar version

POJ 3050 Hopscotch (穷竭搜索)

题目链接:http://poj.org/problem?id=3050 题面: Hopscotch Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2563   Accepted: 1823 Description The cows play the child's game of hopscotch in a non-traditional way. Instead of a linear set of numbered

POJ River Hopscotch(最大值最小化)

River Hopscotch 题目链接:Click Here~ 题目分析: 给出N坐标,固定起点(0)终点在L处(题目给出)要求删除M个坐标,使得剩下的相邻的两个坐标之间的最小距离的值最大.求这个最大值. 思路分析: 不知道为什么就是想到了用二分枚举这个最小距离最大的值,以下我们假设为D.要如何去做呢? 1.首先,我们可以用二分得到这个D. 2.根据函数C:可以满足条件的最大距离 #include <iostream> #include <algorithm> #include

POJ 3050 Hopscotch 水~

http://poj.org/problem?id=3050 题目大意: 在一个5*5的格子中走,每一个格子有个数值,每次能够往上下左右走一格,问走了5次后得到的6个数的序列一共同拥有多少种?(一開始站的位置算一个,能够走回去) 思路: 近期我就是在做水题... 直接DFS就可以..我用map推断序列是否反复的. #include<cstdio> #include<cstring> #include<map> #include<string> #includ

poj 3050 Hopscotch 【DFS】

Hopscotch Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2156   Accepted: 1548 Description The cows play the child's game of hopscotch in a non-traditional way. Instead of a linear set of numbered boxes into which to hop, the cows creat

poj 3050 Hopscotch【搜索、去重】

点击打开题目 Hopscotch Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2126   Accepted: 1524 Description The cows play the child's game of hopscotch in a non-traditional way. Instead of a linear set of numbered boxes into which to hop, the cow

POJ 3050 Hopscotch DFS

The cows play the child's game of hopscotch in a non-traditional way. Instead of a linear set of numbered boxes into which to hop, the cows create a 5x5 rectilinear grid of digits parallel to the x and y axes. They then adroitly hop onto any digit in

poj 3050 Hopscotch

水题,顺带学个stl的set怎么用. set用法 http://www.cnblogs.com/luosuo10/p/5479668.html 1 #include <iostream> 2 #include <set> 3 #include <cstdio> 4 using namespace std; 5 int temp; 6 set <int> s; 7 int dx[]={0,0,-1,1}; 8 int dy[]={1,-1,0,0}; 9 in

《挑战程序设计竞赛》第二章

2.1 最基础的穷竭搜索 poj 2386  Lake Counting(裸dfs) 题意:n*m的矩阵 W是水 .是地 问有多少池塘.(池塘的定义是: W通过八个方向连接成的一片算作是一个池塘.) 1 #include <iostream> 2 using namespace std; 3 #include <cstdio> 4 const int maxn = 100 + 5; 5 int n, m; 6 char ma[maxn][maxn]; 7 int dx[] = {-