标签:style blog color io for div sp log on
简单模拟,注意并不是完全按照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
标签:style blog color io for div sp log on
原文地址:http://www.cnblogs.com/bombe1013/p/3970695.html