1014. Waiting in Line (模拟)
n个窗口就有n个队列,模拟这n个队列就可以了。需要注意的是,一个人在选择排队窗口的时候,他会选择排队人数最少的窗口,如果存在多个窗口排队的人数相同,那么他会选择编码最小的窗口。
Note that since the bank is closed everyday after 17:00, for those customers who cannot be served before 17:00, you must output "Sorry" instead.这句话的意思就是:对于那些不能再17:00之前开始服务的人,请输入"Sorry"。换句话说,就是那些能在五点钟之前开始服务及时服务结束时间超过五点也是可以的!!!所以在计算时,假设$f(i)$表示第$i$个用户结束服务的时间,$serv(i)$表示用户的服务时间,如果满足条件$f(i) - serv(i) \ge (17 - 8) \times 60$,则该客户不能完成服务!!
AC代码
1 #include <stdio.h> 2 #include <string.h> 3 #include <algorithm> 4 using namespace std; 5 #define INF 0x3f3f3f3f 6 const int maxn = 1000 + 5; 7 int n, m, k, q; 8 int serv[maxn], done[maxn]; 9 int line[25][maxn], s[maxn], f[maxn]; 10 11 int main() { 12 while(scanf("%d%d%d%d", &n, &m, &k, &q) == 4) { 13 for(int i = 1; i <= k; i++) 14 scanf("%d", &serv[i]); 15 for(int i = 1; i <= n; i++) { 16 s[i] = f[i] = 1; 17 done[i] = serv[i]; 18 line[i][1] = i; 19 } 20 for(int i = n+1; i <= k; i++) { 21 bool full = 1; 22 int cnt = m + 1, bet = 1; 23 for(int j = 1; j <= n; j++) { 24 if(f[j] - s[j] + 1 < m) { 25 full = 0; 26 if(f[j] - s[j] + 1 < cnt) { 27 cnt = f[j] - s[j] + 1; 28 bet = j; 29 } 30 } 31 } 32 if(full) { 33 int over_time = INF; 34 bet = 1; 35 for(int j = 1; j <= n; j++) { 36 int id = line[j][s[j]]; 37 if(done[id] < over_time) { 38 bet = j; 39 over_time = done[id]; 40 } 41 } 42 s[bet] += 1; 43 } 44 f[bet] += 1; 45 line[bet][f[bet]] = i; 46 done[i] = done[line[bet][f[bet]-1]] + serv[i]; 47 48 } 49 int qID; 50 for(int i = 0; i < q; i++) { 51 scanf("%d", &qID); 52 if(done[qID] - serv[qID] >= (17-8)*60) 53 printf("Sorry\n"); 54 else 55 printf("%02d:%02d\n", done[qID]/60+8, done[qID]%60); 56 } 57 } 58 return 0; 59 }
如有不当之处欢迎指出!