【HDOJ】4884 TIANKENG's rice shop

简单模拟,注意并不是完全按照FIFO的顺序。比如第i个人的id为k,那么就算第i+1人的id不为k,也会检查他后续的排队人是否有id为k的。

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <cstdlib>
 4
 5 #define MAXN 1005
 6
 7 typedef struct {
 8     int tt;
 9     int id;
10     int num;
11     int ans;
12 } need_st;
13
14 need_st needs[MAXN];
15
16 int main() {
17     int t, n, k, m, T;
18     int i, j, hh, mm, tt, tmp;
19
20     scanf("%d", &T);
21     while (T--) {
22         scanf("%d%d%d%d", &n,&t,&k,&m);
23         for (i=0; i<m; ++i) {
24             scanf("%d:%d %d %d", &hh, &mm, &needs[i].id, &needs[i].num);
25             needs[i].tt = 60*hh+mm;
26         }
27         tt = 0;
28         for (i=0; i<m; ++i) {
29             if (needs[i].num == 0)
30                 continue;
31             if (tt < needs[i].tt)
32                 tt = needs[i].tt;
33             tmp = needs[i].num%k;
34             tt += needs[i].num/k*t;
35             if (tmp > 0) {
36                 for (j=i+1; j<m&&needs[j].tt<=tt; ++j) {
37                     if (needs[j].id == needs[i].id) {
38                         if (needs[j].num+tmp > k) {
39                             needs[j].num -= (k-tmp);
40                             break;
41                         } else {
42                             tmp += needs[j].num;
43                             needs[j].num = 0;
44                             needs[j].ans = tt+t;
45                         }
46                     }
47                 }
48                 tt += t;
49             }
50             needs[i].ans = tt;
51         }
52         for (i=0; i<m; ++i)
53             printf("%02d:%02d\n", needs[i].ans/60%24, needs[i].ans%60);
54         if (T)
55             printf("\n");
56     }
57
58     return 0;
59 }

【HDOJ】4884 TIANKENG's rice shop

时间: 2024-10-11 11:28:19

【HDOJ】4884 TIANKENG's rice shop的相关文章

【HDOJ】4122 Alice&#39;s mooncake shop

RMQ的基础题目,简单题. 1 /* 4122 */ 2 #include <iostream> 3 #include <sstream> 4 #include <string> 5 #include <map> 6 #include <queue> 7 #include <set> 8 #include <stack> 9 #include <vector> 10 #include <deque>

[ACM] HDU 4884 TIANKENG’s rice shop (模拟)

TIANKENG's rice shop Problem Description TIANKENG managers a pan fried rice shop. There are n kinds of fried rice numbered 1-n. TIANKENG will spend t time for once frying. Because the pan is so small, TIANKENG can fry k bowls of fried rice with same

hdu 4884 TIANKENG’s rice shop(模拟)

# include <cstdio> # include <algorithm> # include <cstring> # include <cstdlib> using namespace std; int max(int a,int b) { return a>b?a:b; } int main() { int T,n,t,k,m,i,hh,min,id,num,x; int last[1010];//最后一次開始炒饭的时间 int cot[10

HDU TIANKENG’s rice shop(模拟)

HDU 4884 TIANKENG's rice shop 题目链接 题意:模拟题.转一篇题意 思路:就模拟就可以.注意每次炒完之后就能够接单 代码: #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int N = 1005; int T, n, t, k, m; struct Person { int t, p, num, ans; } p[N];

hdu4884 TIANKENG’s rice shop【模拟】

TIANKENG's rice shop Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 345    Accepted Submission(s): 71 Problem Description TIANKENG managers a pan fried rice shop. There are n kinds of fried ri

【HDOJ】4956 Poor Hanamichi

基本数学题一道,看错位数,当成大数减做了,而且还把方向看反了.所求为最接近l的值. 1 #include <cstdio> 2 3 int f(__int64 x) { 4 int i, sum; 5 6 i = sum = 0; 7 while (x) { 8 if (i & 1) 9 sum -= x%10; 10 else 11 sum += x%10; 12 ++i; 13 x/=10; 14 } 15 return sum; 16 } 17 18 int main() { 1

【HDOJ】1099 Lottery

题意超难懂,实则一道概率论的题目.求P(n).P(n) = n*(1+1/2+1/3+1/4+...+1/n).结果如果可以除尽则表示为整数,否则表示为假分数. 1 #include <cstdio> 2 #include <cstring> 3 4 #define MAXN 25 5 6 __int64 buf[MAXN]; 7 8 __int64 gcd(__int64 a, __int64 b) { 9 if (b == 0) return a; 10 else return

【HDOJ】2844 Coins

完全背包. 1 #include <stdio.h> 2 #include <string.h> 3 4 int a[105], c[105]; 5 int n, m; 6 int dp[100005]; 7 8 int mymax(int a, int b) { 9 return a>b ? a:b; 10 } 11 12 void CompletePack(int c) { 13 int i; 14 15 for (i=c; i<=m; ++i) 16 dp[i]

【HDOJ】3509 Buge&#39;s Fibonacci Number Problem

快速矩阵幂,系数矩阵由多个二项分布组成.第1列是(0,(a+b)^k)第2列是(0,(a+b)^(k-1),0)第3列是(0,(a+b)^(k-2),0,0)以此类推. 1 /* 3509 */ 2 #include <iostream> 3 #include <string> 4 #include <map> 5 #include <queue> 6 #include <set> 7 #include <stack> 8 #incl