2022-08-07 米哈游笔试统计~程序综合笔试A卷
1.史莱姆队列
2.跳石头得分
3.树中abb类型个数
22.20更新
1. #include <bits/stdc++.h> using namespace std; int main() { unordered_map<char, int>mp; int T; cin >> T; queue<char>q; int ans = 0; while(T--) { int x; cin >> x; if(x == 1) { char c; cin >> c; q.push(c); if(mp[c] == 0) ans++; mp[c]++; } else if(x == 2) { char c = q.front(); q.pop(); mp[c]--; if(mp[c] == 0) ans--; } else { cout << ans << endl; } } return 0; } 2. #include <bits/stdc++.h> using namespace std; int a[100005]; int b[100005]; int main() { int n, m; cin >> n >> m; for(int i = 0; i < n; i++) { cin >> a[i]; } for(int i = 0; i < m; i++) { cin >> b[i]; } int ans = 0; for(int i = 0; i < n; i++) { if(b[a[i] - 1] > 0) { ans++; b[a[i] - 1]--; } else { break; } } cout << ans * 30 << endl; return 0; } 3. #include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; vector<vector<int>>same(n); vector<vector<int>>different(n); int x, y; for(int i = 0; i < n - 1; i++) { cin >> x >> y; if(s[x - 1] == s[y - 1]) { same[x - 1].push_back(y - 1); same[y - 1].push_back(x - 1); } else { different[x - 1].push_back(y - 1); different[y - 1].push_back(x - 1); } } long long ans = 0; for(int i = 0; i < n; i++) { for(auto &j: different[i]) { ans += same[j].size(); } } cout << ans << endl; return 0; } /* */