cf767B. The Queue

本文分享了一段针对特定ACM竞赛题目的代码实现过程及解析,通过简洁的代码解决了复杂的问题,并详细记录了从理解题目到调试代码直至最终解决的过程。

题目
题解
细节特别多,写完以后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);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值