CodeForces 767B The Queue
Posted Fighting Heart
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CodeForces 767B The Queue相关的知识,希望对你有一定的参考价值。
模拟。
情况有点多,需要仔细。另外感觉题目的$tf$有点不太对......而且数据水了。
$0$ $5$ $2$
$2$
$0$ $5$
这组数据按照题意的话答案可以是$2$和$4$,但是好多错的答案能$AC$。
#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #include<map> #include<set> #include<queue> #include<stack> #include<ctime> #include<iostream> using namespace std; typedef long long LL; const double pi=acos(-1.0); void File() { freopen("D:\\in.txt","r",stdin); freopen("D:\\out.txt","w",stdout); } template <class T> inline void read(T &x) { char c = getchar(); x = 0; while(!isdigit(c)) c = getchar(); while(isdigit(c)) { x = x * 10 + c - ‘0‘; c = getchar(); } } LL INF=0x7FFFFFFF; LL ts,tf,t; int n; LL s[100010]; int main() { INF=INF*INF; INF=INF*2; scanf("%lld%lld%lld",&ts,&tf,&t); scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%lld",&s[i]); if(n==0) { printf("%lld\n",ts); return 0; } if(s[1]>ts) { printf("%lld\n",ts); return 0; } LL need=INF,idx=-1,last=ts,tmp; last=max(last,s[1])+t; for(int i=2;i<=n;i++) { if(s[i]==s[i-1]) { last=max(last,s[i])+t; continue; } if(s[i-1]<=tf) { tmp=last+t; if(tmp<=tf&&tmp-s[i-1]<need) idx=s[i-1],need=tmp-s[i-1]; } if(s[i]-1<=tf) { tmp=max(s[i]-1,last)+t; if(tmp<=tf&&tmp-(s[i]-1)<need) idx=s[i]-1,need=tmp-(s[i]-1); } if(last>=s[i-1]&&last<s[i]) { tmp=last+t; if(tmp<=tf&&tmp-last<need) idx=last,need=tmp-last; } last=max(last,s[i])+t; } if(s[1]!=0) { tmp=ts+t; if(0<=tf) { if(tmp<=tf&&tmp-0<need) idx=0,need=tmp-0; } tmp=max(s[1]-1,ts)+t; if(s[1]-1<=tf) { if(tmp<=tf&&tmp-(s[1]-1)<need) idx=s[1]-1,need=tmp-(s[1]-1); } } tmp=last+t; if(s[n]<=tf) { if(tmp<=tf&&tmp-s[n]<need) idx=s[n],need=tmp-s[n]; } if(last<=tf) { if(tmp<=tf&&tmp-last<need) idx=last,need=tmp-last; } printf("%lld\n",idx); return 0; }
以上是关于CodeForces 767B The Queue的主要内容,如果未能解决你的问题,请参考以下文章
CodeForces 625B War of the Corporations
CodeForces 625A Guest From the Past
The Shortest Statement CodeForces - 1051F(待测试)