AOJ 1124 When Can We Meet?
問題
When Can We Meet? | Aizu Online Judge
- 会議参加者の都合が良い日のリストが与えられるので、最も多くの人が参加できる一番早い日程を決める
- 定足数に達する日がある開催日を出力、達しなければ0を出力
方針
日付から参加人数を求めるmapを作って最大値を求める
コード
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for(int i=0; i<(n); ++i) int main(void){ int N, Q, M, d; map<int, int> date; while(cin >> N >> Q && N) { date.clear(); rep(i, N) { cin >> M; rep(j, M) { cin >> d; date[d]++; } } map<int, int>::iterator it = date.begin(); int size = 0, ans=numeric_limits<int>::max(); while(it != date.end()) { if(size < (*it).second || (size == (*it).second && ans > (*it).first)) { size = (*it).second; ans = (*it).first; } it++; } if(size >= Q) cout << ans << endl; else cout << 0 << endl; } }
http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=1886818
反省
- iteratorはfor文で書いた方がきれいっぽい(chokudai本はwhile文だった)