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;
    }
  • 相关阅读:
    A Node Influence Based Label Propagation Algorithm for Community detection in networks 文章算法实现的疑问
    Fast Newman-FN算法以及模块度定义介绍
    Label Propagation Algorithm LPA 标签传播算法解析及matlab代码实现
    设计一个smartnic
    Intel GEN11 GPU
    Intel GEN9 GPU
    Shared Virtual Memory (SVM) Functions
    connect via ssh to virtualbox guest vm without knowing ip address
    smartnic
    技术精品翻译
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7626502.html
Copyright © 2011-2022 走看看