码迷,mamicode.com
首页 > 其他好文 > 详细

CodeForces 767B The Queue

时间:2017-02-19 12:36:01      阅读:226      评论:0      收藏:0      [点我收藏+]

标签:ret   map   void   oid   get   stream   ios   name   etc   

模拟。

情况有点多,需要仔细。另外感觉题目的$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

标签:ret   map   void   oid   get   stream   ios   name   etc   

原文地址:http://www.cnblogs.com/zufezzt/p/6415351.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!