AOJ 1074 - Popularity Estimation

http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1074

解法

0 <= m <= 30 だからやるだけ.

 1 #include <iostream>
 2 #include <vector>
 3 #include <algorithm>
 4 using namespace std;
 5 
 6 int main()
 7 {
 8   int N;
 9   while (cin >> N && N != 0) {
10     vector<vector<int> > v(30);
11     vector<pair<int,string> > scores(N);
12     for (int i = 0; i < N; i++) {
13       int c;
14       scores[i].first = 0;
15       cin >> scores[i].second >> c;
16       for (int j = 0; j < c; j++) {
17         int m;
18         cin >> m;
19         v[m].push_back(i);
20       }
21     }
22     for (int i = 0; i < 30; i++) {
23       const int s = N - v[i].size() + 1;
24       for (vector<int>::const_iterator it = v[i].begin(); it != v[i].end(); ++it) {
25         scores[*it].first += s;
26       }
27     }
28     sort(scores.begin(), scores.end());
29     cout << scores[0].first << ' ' << scores[0].second << endl;
30   }
31   return 0;
32 }
aoj/1074.cc