cf767B. The Queue

题目
题解
细节特别多,写完以后wa了三四发以后实在想不出哪里漏想了,就看数据,又wa了好几发,实在不行,就看了题解
程序其实很短

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=100002;
int i,n;
ll x,s,ans,t,e,mx,mn;
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
    ll x=0,fl=1;char ch=gc();
    for (;ch<48||ch>57;ch=gc())if(ch=='-')fl=-1;
    for (;48<=ch&&ch<=57;ch=gc())x=(x<<3)+(x<<1)+(ch^48);
    return x*fl;
}
int main(){
    s=read();e=read();t=read();n=read();
    ans=mn=1e15;
    for (i=0;i<n;i++){
        x=read();
        if (!x || x+t>e) continue;
        mx=max(x,s);
        if (mx+t<=e && s-(x-1)<mn){
            mn=s-(x-1);
            ans=min(x-1,s);
        }
        s=max(s,x)+t;
    }
    if (s+t<=e) ans=s;
    printf("%I64d",ans);
}

猜你喜欢

转载自blog.csdn.net/xumingyang0/article/details/80957324