Sina Weibo has a "quiet focus". A person that a user quietly Watches does not appear on the user's attention list, but the system will push the Weibo published by the person that he quietly watches to the user. Now let's do a web detective to pick out people who might be quietly watched by someone based on their attention list and how they like other users.
Input format:
Input first gives a user's list of concerns in the first line in the following format:
Number of people N User 1 User 2...User N
Among them, N is a positive integer of no more than 5,000. Each user I (i=1,..., N) is the ID of the user it is interested in. It is a 4-digit string of numbers and letters separated by spaces.
Then give the user's favorite information: first give a positive integer M not exceeding 10000, then M inserts a code snippet line here, each line gives a user ID that is favored by the user and the number of times the user is favored (no more than 1000), separated by a space. Note: The user ID is the unique identity of a user. Title guarantees that there are no duplicate users in the attention list and no duplicate users in the comments.
Output format:
We think people who get more favors from this user than their average number and aren't on their attention list are probably the ones they quietly follow. Based on this assumption, the alphabetical ascending output of user IDs may be the person they are quietly following, one ID per line. If there is no such person, output "Bing Mei You".
Input Sample 1:
10 GAO3 Magi Zha1 Sen1 Quan FaMK LSum Eins FatM LLao 8 Magi 50 Pota 30 LLao 3 Ammy 48 Dave 15 GAO3 31 Zoro 1 Cath 60 No empty line at end
Output Sample 1:
Ammy Cath Pota No empty line at end
Input Sample 2:
11 GAO3 Magi Zha1 Sen1 Quan FaMK LSum Eins FatM LLao Pota 7 Magi 50 Pota 30 LLao 48 Ammy 3 Dave 15 GAO3 31 Zoro 29
Output Sample 2:
Bing Mei You
Spam Code: Run Timeout T_T
#include <bits/stdc++.h> using namespace std; struct person { string id; int num; }; vector<string> s2; bool cmp(int x, int y) { return strcmp(s2[x].c_str(), s2[y].c_str()) < 0; } int main() { int N; cin >> N; vector<string> s1; for(int i = 0; i < N; i++) { string temp; cin >> temp; s1.push_back(temp); } int M; cin >> M; person p[M]; int adv = 0; for(int i = 0; i < M; i++) { cin >> p[i].id; cin >> p[i].num; adv += p[i].num; } adv /= M; for(int i = 0; i < M; i++) { if(p[i].num > adv) { int j; for(j = 0; j < N; j++) { if(p[i].id == s1[j]){ break; } } if(j == N) { s2.push_back(p[i].id); } } } int len = s2.size(); if(len == 0) { cout << "Bing Mei You"; } else { int pos[len]; for(int i = 0; i < len; i++) { pos[i] = i; } sort(pos, pos + len, cmp); for(int i = 0; i < len; i++) { cout << s2[pos[i]]; if(i != s2.size() - 1) { cout << endl; } } } return 0; }
AC code:
#include <bits/stdc++.h> using namespace std; int main() { int N, M; set<string> list; map<string, int> zan;// map direct ascending storage is wonderful!! cin >> N; string id; int num; int adv = 0; for(int i = 0; i < N; i++) { cin >> id; list.insert(id); } cin >> M; for(int i = 0; i < M; i++) { cin >> id >> num; zan[id] = num; adv += num; } adv /= M; vector<string> s; for(auto it : zan) // Automatic Match Type { if((it.second > adv) && (list.find(it.first) == list.end())) { s.push_back(it.first); } } int len = s.size(); if(len == 0) { cout << "Bing Mei You"; } else { for(int i = 0; i < len; i++) { cout << s[i]; if(i != len - 1) { cout << endl; } } } return 0; }