zoukankan      html  css  js  c++  java
  • POJ3258-River Hopscotch-二分答案

    一条河里有一串石头,给出石头间的间距,让你去掉m个石头,使最短间距最大。

    二分答案,对于每一种mid,判断要不要删除这块石头。然后逼近答案。

    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    
    using namespace std;
    
    int dist[50010],save[50010],L,N,M;
    
    int main()
    {
        while(~scanf("%d%d%d",&L,&N,&M))
        {
            int low = L,high = L;
            for(int i=0;i<N;i++)
            {
                scanf("%d",&dist[i]);
                low = min(low,dist[i]-dist[i-1]);
            }
            dist[N] = 0;
            dist[N+1] = L;
            N+=2;
            sort(dist,dist+N);
    
            int mid = (low+high)>>1;
    
            while(low <= high)
            {
                int rmv = 0,sum=0;
                for(int i=1;i<N;i++)
                {
                    if(sum+dist[i]-dist[i-1] <= mid)
                    {
                        rmv++;
                        sum+=dist[i]-dist[i-1];
                    }
                    else
                    {
                        sum=0;
                    }
                }
    
                if(rmv > M)
                    high = mid-1;
                else
                    low = mid+1;
    
                mid = (low+high)>>1;
            }
            printf("%d
    ",low);
        }
    }
  • 相关阅读:
    Zepto源码分析-动画(fx fx_method)模块
    CSS3用法理解
    移动端网页meta设置和响应式
    javascript基础-正则表达式
    net core 2.x
    angular
    .net core 2.x
    .net core 2.x
    DDD
    DDD
  • 原文地址:https://www.cnblogs.com/helica/p/5173797.html
Copyright © 2011-2022 走看看