zoukankan      html  css  js  c++  java
  • 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
    ",l);
        }
        return 0;
    }
    View Code
  • 相关阅读:
    钟国晨160809323(作业5)
    12
    11
    第九次
    8作业
    第七次作业
    6
    林昊5
    计算机网络原理与应用笔记 3/29
    计算机网络原理与应用笔记 3/22
  • 原文地址:https://www.cnblogs.com/jihe/p/5572168.html
Copyright © 2011-2022 走看看