5个小时的debug体验,很酸了(一开始把m和n弄混,后来又发现只要在540之前接受服务就可以算成功。解法十分的粗暴,一分钟判断一次的逻辑.....代码不算复杂,细节比较恼人,不适合我这种无脑马大哈
1 #include <iostream> 2 #include <vector> 3 #include <queue> 4 5 using namespace std; 6 7 int main(void) 8 { 9 //queue<int> wait; 10 11 int n, m, k, q; 12 cin >> n >> m >> k >> q; 13 vector<int> cost_time(k + 2);//end 14 vector<int> beg_time(k + 2, 541);//开始被服务 15 for (int i = 0;i < k;i++) 16 cin >> cost_time[i]; 17 vector<queue<int> > win(n); 18 for (int i = 0;i < n;i++)//第一批入黄线 19 { 20 if(i<k)//记得加判断,有一个测试点n>k 21 beg_time[i] = 0; 22 for (int j = 0;j < m;j++) 23 { 24 if (n*j + i >= k)break; 25 win[i].push(n*j + i); 26 } 27 } 28 29 30 int next = n*m;//下一个入队,也有k<n*m的情况,不过下面做了判断 31 for (int times = 1;times<540;times++) 32 { 33 for (int w = 0;w < n;w++) 34 { 35 if (win[w].empty())continue; 36 int cus = win[w].front(); 37 if (cost_time[cus] == times&&beg_time[cus] < 540) 38 { 39 win[w].pop(); 40 41 if (next < k)win[w].push(next++); 42 if (!win[w].empty()) 43 { 44 cost_time[win[w].front()] += cost_time[cus]; 45 beg_time[win[w].front()] = cost_time[cus]; 46 } 47 } 48 } 49 } 50 //give ans 51 for (int i = 0;i < q;i++) 52 { 53 int query; 54 cin >> query; 55 if (beg_time[query - 1] >= 540) 56 { 57 printf("Sorry "); 58 continue; 59 } 60 61 int h = 8 + cost_time[query - 1] / 60, m = cost_time[query - 1] % 60; 62 printf("%02d:%02d ", h, m); 63 } 64 65 return 0; 66 }