zoukankan      html  css  js  c++  java
  • https://vjudge.net/problem/Gym-100801J/origin

    二分答案出最小距离,dpcheck,单调队列优化dp

    #include <iostream>
    #include <cstdio>
    #include <queue>
    #include <algorithm>
    #include <cmath>
    #include <cstring>
    #define inf 2147483647
    #define N 1000010
    #define p(a) putchar(a)
    #define For(i,a,b) for(long long i=a;i<=b;++i)
    
    using namespace std;
    long long n,T,l,r,mid,ans;
    long long p[N],t[N],q[N],f[N];
    void in(long long &x){
        long long y=1;char c=getchar();x=0;
        while(c<'0'||c>'9'){if(c=='-')y=-1;c=getchar();}
        while(c<='9'&&c>='0'){ x=(x<<1)+(x<<3)+c-'0';c=getchar();}
        x*=y;
    }
    void o(long long x){
        if(x<0){p('-');x=-x;}
        if(x>9)o(x/10);
        p(x%10+'0');
    }
    
    bool check(long long x){
        long long l=1,r=0;
        memset(q,0,sizeof(q));
        memset(f,0,sizeof(f));
        For(i,1,n){
            while(l<=r&&q[r]-q[l]>=x) l++;
            f[i]=f[q[l]]+t[i];
            while(l<=r&&f[q[r]]>=f[i]) r--;
            q[++r]=i;
        }
        if(f[n]+n-1<=T) return 1;
        else return 0;
    }
    
    signed main(){
        freopen("journey.in","r",stdin);
        freopen("journey.out","w",stdout);
        in(n);in(T);
        For(i,1,n-1) in(p[i]);
        For(i,2,n-1) in(t[i]);
        l=1;r=n;
        while(l<r){
            mid=(l+r)>>1;
            if(check(mid)) r=mid;
            else l=mid+1;
        }
        ans=p[l];
        For(i,l+1,n-1) ans=min(ans,p[i]);
        o(ans);
        return 0;
    }
  • 相关阅读:
    谷歌浏览器解决跨域
    实现Linux共享Window文件
    linux安装显卡驱动
    jsduck 文档生成器
    linux 笔记
    Linux phpstorm 无法输入中文
    linux 安装composer
    Extjs动态生成表头(适用报表)
    关于git的配置与使用
    JSP解决中文乱码问题
  • 原文地址:https://www.cnblogs.com/war1111/p/12526656.html
Copyright © 2011-2022 走看看