1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
| #include<iostream> #include<cstring> #include<unordered_map> #include<vector> #include<algorithm> using namespace std; struct customer { char name[4]; int arriveTime, processTime; }; int N, M; unordered_map<string, int> friendMap, customerId; bool visited[10000]; vector<string> friends[100], result; bool cmp(string s1, string s2); int main() { scanf("%d %d", &N, &M); fill(visited, visited + N, false); for(int i = 0; i < M; i++) { int L; scanf("%d", &L); for(int j = 0; j < L; j++) { char name[4]; scanf("%s", name); friendMap[name] = i; friends[i].push_back(name); } } customer customers[N]; for(int i = 0; i < N; i++) { char name[4]; scanf("%s %d %d", name, &customers[i].arriveTime, &customers[i].processTime); if(customers[i].processTime > 60) { customers[i].processTime = 60; } strcpy(customers[i].name, name); customerId[name] = i; } int totalTime = 0; int window = customers[0].arriveTime; for(int i = 0; i < N; i++) { if(visited[i]) { continue; } if(friendMap.find(customers[i].name) == friendMap.end()) { if(window > customers[i].arriveTime) { totalTime += window - customers[i].arriveTime; window += customers[i].processTime; }else{ window = customers[i].arriveTime + customers[i].processTime; } visited[i] = true; result.push_back(customers[i].name); continue; } int friendID = friendMap[customers[i].name]; sort(friends[friendID].begin(), friends[friendID].end(), cmp); for(int j = 0; j < friends[friendID].size(); j++) { int id = customerId[friends[friendID][j]]; if(j > 0 && customers[id].arriveTime > window){ break; } if(visited[id]){ continue; } if(window > customers[id].arriveTime) { totalTime += window - customers[id].arriveTime; window += customers[id].processTime; } else { window = customers[id].arriveTime + customers[id].processTime; } visited[id] = true; result.push_back(friends[friendID][j]); } } for(int i = 0; i < result.size(); i++) { printf("%s\n", result[i].c_str()); } printf("%.1f\n", totalTime * 1.0 / N); return 0; } bool cmp(string s1, string s2) { return customerId[s1] < customerId[s2]; }
|