• [NOIP 2015] 跳石头


    [题目链接]

              http://uoj.ac/problem/148

    [算法]

             二分答案,时间复杂度O(NlogL)

    [代码]

            

    #include<bits/stdc++.h>
    using namespace std;
    #define MAXN 50010
    typedef long long ll;
    
    ll i,L,N,M,l,r,mid,ans;
    ll dis[MAXN];
    
    template <typename T> inline void read(T &x)
    {
            ll f = 1; x = 0;
            char c = getchar();
            for (; !isdigit(c); c = getchar())
            {
                    if (c == '-') f = -f;
            }
            for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
            x *= f;
    }
    inline bool check(ll d)
    {
            ll i,c = 0,cnt = 0;
            bool flag = false;
            for (i = 1; i <= N; i++)
            {
                    if (dis[i] - dis[c] >= d) c = i;        
                    else cnt++;
                    if (cnt > M) return false;
            }
            if (L - dis[c] < d) cnt++;
            if (cnt <= M) return true;
            return false;
    }
    
    int main() 
    {
            
            read(L); read(N); read(M);
            dis[0] = 0;
            for (i = 1; i <= N; i++) read(dis[i]);
            l = 1; r = 1e15;
            while (l <= r)
            {
                    mid = (l + r) >> 1;
                    if (check(mid))
                    {
                            l = mid + 1;
                            ans = mid; 
                    } else r = mid - 1;
            }
            printf("%lld
    ",ans);
            
            return 0;
        
    }
  • 相关阅读:
    nginx平滑升级及回滚
    redis源码安装
    memcached安装
    Harbor源码部署
    Maven源码部署
    tomcat单机多实例(未完待续)
    部署tomcat
    nginx编译参数详解
    CentOS7 安装pip/pip3
    nginx 部署配置
  • 原文地址:https://www.cnblogs.com/evenbao/p/9470884.html
Copyright © 2020-2023  润新知