TIANKENG’s rice shop
Total Submission(s): 1315 Accepted Submission(s): 326
For each test case, the first line has 4 positive integer n(1<=n<=1000), t(1<=t<=10), k(1<=k<=5), m(1<=m<=1000), then following m lines , each line has a time(the time format is hh:mm, 0<=hh<=23, 0<=mm<=59) and two positive integer id(1<=id<=n), num(1<=num<=10), which means the brand number of the fried rice and the number of the fried rice the customer needs.
Pay attention that two or more customers will not come to the shop at the same time, the arriving time of the customer will be ordered by the time(from early time to late time)
3 2 1 4 2 08:00 1 5 09:00 2 1 2 5 4 3 08:00 1 4 08:01 2 2 08:02 2 2 2 5 4 2 08:00 1 1 08:04 1 1
08:02 09:01 08:05 08:10 08:10 08:05 08:10
题意,就是有N种炒饭,每次炒的时间是t分钟,每次最多炒k份,然后按照进店的顺序给出m个顾客的信息,进店时间,炒饭的编号以及份数。然后要输出每个顾客离开的时间。
题目中告诉了我们炒饭的规则,按照先来先服务,但是每次炒会炒尽可能多的份数,不过不会有多余的。
举个例子,比如每次可以炒5份,每次5分钟。
第一个顾客08:00进来,点了2份A,
第二个顾客08:04进来,点了3份A。
在08:00开始炒的话,由于这个时候第二个顾客还没进来,所以就只炒2份,第一个顾客在08:05离开,这时才炒第二个的3份,所以第二个离开时间是08:10。
同样是每次可以炒5份,每次5分钟。
第一个顾客08:00进来,点了6份A,
第二个顾客08:01进来,点了5份B,
第三个顾客08:02进来,点了4份A。
同样地,先炒5份给第一个,还差一份,这是已经是08:05了,第三个顾客也进来了,所以这时直接炒5份A(因为会尽可能多地炒),08:10第一个和第三个可以同时离开。接着才炒第二个的。
具体模拟的话,我是用一个cnt[i]表示编号i的炒饭还剩下多少份,并且最后一次炒的时间last[i]。
那么读到一个时间hh:mm,先判断这个编号的炒饭有没有剩余,进来的时间是否比最后一次炒的时间早,只有比这个时间早才有可能提前为他炒。
如果剩余的数量足以供应了,就直接输出last[i]+t
否则求出剩余的量还需要的时间,并且更新cnt[i]和last[i]。
#include <iostream>
#include <set>
#include <map>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <bitset>
#include <string>
#include <vector>
#include <iomanip>
#include <cstring>
#include <algorithm>
#include <functional>
#define PI acos(-1)
#define eps 1e-8
#define inf 0x3f3f3f3f
#define debug(x) cout<<"---"<<x<<"---"<<endl
typedef long long ll;
using namespace std;
int a[1010];
int main()
{
int gg;
cin >> gg;
while (gg--)
{
memset(a, 0, sizeof(a));
int n, t, k, hh;
cin >> n >> t >> k >> hh;
for (int i = 0; i < hh; i++)
{
int h, m, kind, countt, wt=0;
scanf("%d:%d%d%d", &h, &m, &kind, &countt);
if (a[kind] >= countt)
{
a[kind] -= countt;
countt = 0;
wt = 0;
}
else
{
countt -= a[kind];
a[kind] = 0;
}
if (countt % k == 0 && countt)
{
wt += (countt / k) * t;
a[kind] += 0;
}
else if (countt % k != 0 && countt)
{
wt += ((countt / k) + 1) * t;
a[kind] += ((countt / k) + 1) * k - countt;
}
m += wt;
if (m >= 60)
{
h++;
if (h == 25)
{
h = 1;
}
m -= 60;
}
if (h >= 0 && h <= 9)
{
printf("0%d:", h);
}
else
{
printf("%d", h);
}
if (m >= 0 && m <= 9)
{
printf("0%d\n", m);
}
else
{
printf("%d\n", m);
}
}
cout << endl;
}
return 0;
}
1975




被折叠的 条评论
为什么被折叠?



