zoukankan      html  css  js  c++  java
  • 【codeforces 767B】The Queue

    【题目链接】:http://codeforces.com/contest/767/problem/B

    【题意】

    排队去办护照;
    给你n个人何时来的信息;
    然后问你应该何时去才能在队伍中等待的时间最短;
    (如果你和别人同时到,你要等到和你同时到的人全都办完了才轮到你);

    【题解】

    细节题吧。
    首先大体思路就是;
    枚举那个人在哪个人办完之后办;
    如果那个人办完之后和下一个时间的人之间有空隙->直接输出那个枚举的人办完后的时间->因为这表示等待时间为0的情况;
    否则如果没有空隙,那么就要在下一个时间的人之前一个单位的时间来;
    这样等待的时间尽量最短;
    然后取最小值就好;
    当然还有一种就是在第一个人之前半,或者没有一个人直接在ts时刻来就好;
    这两类取较小值就好;
    坑点:
    题目没讲清楚的就是
    如果在时间点20,服务一个人要10分钟,然后tf=30,那么如果这个时刻来人
    那个人是可以被服务的。
    初始时间要分t[1]< ts和t[1]>=ts两类赋值;

    【完整代码】

    #include <bits/stdc++.h>
    using namespace std;
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define LL long long
    #define rep1(i,a,b) for (int i = a;i <= b;i++)
    #define rep2(i,a,b) for (int i = a;i >= b;i--)
    #define mp make_pair
    #define ps push_back
    #define fi first
    #define se second
    #define rei(x) scanf("%d",&x)
    #define rel(x) scanf("%lld",&x)
    #define ref(x) scanf("%lf",&x)
    
    typedef pair<int, int> pii;
    typedef pair<LL, LL> pll;
    
    const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
    const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
    const double pi = acos(-1.0);
    const int N = 1e5+100;
    
    LL ts,tf;
    LL T[N],now,t,idxtt=-1,tt;
    int n;
    
    int main()
    {
        //freopen("D:\rush.txt", "r", stdin);
        rel(ts),rel(tf);rel(t);
        rei(n);
        rep1(i,1,n)
            rel(T[i]);
        if (T[1]<ts)
        now = ts;
        else
        now = T[1];
        rep1(i,1,n)
        {
            int l = i,r = i;
            while (r+1<=n && T[r+1]==T[l]) r++;
            int num = r-l+1;
            LL extcost=0;
            now+=1LL*t*num;
            if (now+t>tf) break;
            if (r+1<=n)
            {
                if (now<=T[r+1]-1)
                {
                    printf("%lld
    ",now);
                    return 0;
                }
                else
                {
                    if (now>=T[r+1])
                    {
                        LL idx = T[r+1]-1,ttemp = 0;
                        ttemp += now-idx;
                        if (idxtt==-1)
                        {
                            idxtt = idx;
                            tt = ttemp;
                        }
                        else
                            if (tt>ttemp)
                            {
                                idxtt = idx;
                                tt = ttemp;
                            }
                    }
                }
            }
            else
            {
                    printf("%lld
    ",now);
                    return 0;
            }
            i = r;
        }
        if (n==0 || T[1]>ts)
        {
            return printf("%lld
    ",ts),0;
        }
        else
            //t[1]<=ts
        {
            LL spt = T[1]-1;
            LL wait = ts-spt;
            if (idxtt==-1 || wait<tt)
                idxtt = spt;
        }
        printf("%lld
    ",idxtt);
        //printf("
    %.2lf sec 
    ", (double)clock() / CLOCKS_PER_SEC);
        return 0;
    }
  • 相关阅读:
    认识Cookie和状态管理
    python之requests库使用问题汇总
    如何掌握所有的程序语言--王垠
    非 GUI 模式运行 JMeter 压力测试
    Python 如何将字符串转为字典
    python之operator操作符函数
    python3使用xlrd、xlwt、xlutils、openpyxl、xlsxwriter操作excel
    《敏捷软件测试:测试人员与敏捷团队的实践指南》
    Jmeter跨线程组传递变量
    Jmeter获取当前时间、历史时间、未来时间的方式
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7626502.html
Copyright © 2011-2022 走看看