【郑轻邀请赛 F】 Tmk吃汤饭

【题目链接】:https://acm.zzuli.edu.cn/zzuliacm/problem.php?id=2132

【题意】

【题解】

很容易想到用队列来模拟;
这个队列维护的是正在煮的4个人煮完且可以再重新煮一个的位置;
如果队列是满的;
时间指向队列的头节点;
然后头节点删掉;
在队尾再加上一个t+5;
但是如果可以直接加的话是t+6,因为有1分钟的点餐时间不能省;(上面能省是因为早到了,可以直接开始点,然后等);
一个人一个人地模拟就好.

【Number Of WA

0

【完整代码】

#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 pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof 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 = 110;

int n;
queue <int> dl;

int main()
{
    //freopen("F:\\rush.txt","r",stdin);
    ios::sync_with_stdio(false);
    int T;
    cin >> T;
    while (T--)
    {
        while (!dl.empty()) dl.pop();
        cin >> n;
        rep1(i,1,n)
        {
            int t;
            cin >> t;
            while (!dl.empty() && t>= dl.front()) dl.pop();
            if (int(dl.size())<4)
            {
                dl.push(t+6);
            }
            else
            {
                t = dl.front();
                dl.pop();
                dl.push(t+5);
            }
        }
        cout << dl.back()<<endl;
    }
    //printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
    return 0;
}
posted @ 2017-10-04 18:44  AWCXV  阅读(141)  评论(0编辑  收藏  举报