标签:style http color os io for 问题 ar
题目链接:hdu 4884 TIANKENG’s rice shop
题目大意:TIANKENG开了个饭馆,提供n种炒饭,每次抄需要T的时间,每次可以炒K份,在炒的时候不可以接单,以及时间超过1天的情况。
给组样例:
1
1000 10 3 5
23:00 12 10
23:01 99 9
23:05 100 4
23:10 12 10
23:40 100 10
解题思路:模拟啊,主要是题意比较坑,上面那组样例跑过基本就没有问题了。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 1005;
int N, T, K, M, ans[maxn];
struct state {
int t, id, s;
int ans, flag;
}p[maxn];
void init () {
scanf("%d%d%d%d", &N, &T, &K, &M);
int hh, mm;
for (int i = 0; i < M; i++) {
scanf("%d:%d%d%d", &hh, &mm, &p[i].id, &p[i].s);
p[i].t = hh * 60 + mm;
p[i].flag = 0;
}
}
void solve () {
int tmp = 0;
for (int i = 0; i < M; i++) {
if (p[i].flag)
continue;
int k = (p[i].s + K - 1) / K;
int mv = max(tmp, p[i].t) + (k - 1) * T;
int have = k * K;
for (int j = i; j < M; j++) {
if (p[j].t > mv || have == 0)
break;
if (p[j].id == p[i].id) {
int del = min(have, p[j].s);
have -= del;
p[j].s -= del;
if (p[j].s == 0 && p[j].flag == 0) {
p[j].ans = mv + T;
p[j].flag = 1;
}
}
}
tmp = mv + T;
}
for (int i = 0; i < M; i++)
printf("%02d:%02d\n", (p[i].ans / 60) % 24, p[i].ans % 60);
}
int main () {
int cas;
scanf("%d", &cas);
while (cas--) {
init();
solve();
if (cas)
printf("\n");
}
return 0;
}
hdu 4884 TIANKENG’s rice shop(模拟),布布扣,bubuko.com
hdu 4884 TIANKENG’s rice shop(模拟)
标签:style http color os io for 问题 ar
原文地址:http://blog.csdn.net/keshuai19940722/article/details/38229199