解題心得
檢查b校有沒有a校的申請,有的話案件成立數加一,沒有的話紀錄下來a校想去b校。
程式碼
#include <iostream> #include <map> #include <vector> using namespace std; int main() { int n; while (cin >> n) { map<int, map<int,int>> record; int total = 0; while (n--) { int a, b; cin >> a >> b; if (record.count(b) && record[b].count(a) && record[b][a] > 0) { total++; record[b][a]--; } else { if (!record.count(a) || !record[a].count(b)) record[a][b] = 1; else record[a][b]++; } } cout << total << endl; } return 0; }
沒有留言:
張貼留言