• 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
    ",ts);
            return 0;
        }
    
        if(s[1]>ts)
        {
            printf("%lld
    ",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
    ",idx);
    
        return 0;
    }
  • 相关阅读:
    C++构造与析构 yongmou
    坏习惯 yongmou
    Python 字符串方法
    python 列表推导式轻量级循环
    python 循环遍历字典元素
    python 短路逻辑和条件表达式
    python 迭代器
    一些关于面向对象设计的思考
    python map内建函数
    Python 列表
  • 原文地址:https://www.cnblogs.com/zufezzt/p/6415351.html
Copyright © 2020-2023  润新知