AtCoder Beginner Contest 315
AtCoder Beginner Contest 315
A - tcdr (atcoder.jp)
一次遍历
#include<bits/stdc++.h>
using i64 = long long;
using namespace std;
typedef pair<i64, i64> PII;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
string s, ans = "";
cin >> s;
for (auto i : s) {
if (i != 'a' && i != 'e' && i != 'o' && i != 'u' && i != 'i')
ans += i;
}
cout << ans << '\n';
return 0;
}
B - The Middle Day (atcoder.jp)
每次去比较每个月有没有到达一半的天数即可
#include<bits/stdc++.h>
using i64 = long long;
using namespace std;
typedef pair<i64, i64> PII;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int M;
cin >> M;
vector<int> D(M + 1);
int sum = 0;
for (int i = 1; i <= M; i ++) {
cin >> D[i];
sum += D[i];
}
int now = 0;
sum = (sum + 1) / 2;
for(int i = 1;i<= M;i ++){
if(now + D[i] >= sum){
cout << i << ' ' << sum - now << '\n';
return 0;
}else
now += D[i];
}
return 0;
}
C - Flavors (atcoder.jp)
分别与每个相同口味的美味程度比较以及与不同口味的最大的两个美味程度比较
#include<bits/stdc++.h>
using i64 = long long;
using namespace std;
typedef pair<i64, i64> PII;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
vector<i64> F(N + 1), S(N + 1);
map<int, priority_queue<i64>> mp;
for (int i = 1; i <= N; i ++) {
cin >> F[i] >> S[i];
mp[F[i]].push(S[i]);
}
priority_queue<int> Q;
i64 ans = 0;
for (auto [_, q] : mp) {
Q.push(q.top());
if (q.size() >= 2) {
i64 m1 = q.top();
q.pop();
i64 m2 = q.top();
ans = max(m1 + m2 / 2, ans);
}
}
if (Q.size() > 1) {
i64 M1 = Q.top();
Q.pop();
i64 M2 = Q.top();
ans = max(M1 + M2, ans);
}
cout << ans << '\n';
return 0;
}
E - Prerequisites (atcoder.jp)
直接去递归找每本书需要的前置书
#include<bits/stdc++.h>
using i64 = long long;
using namespace std;
typedef pair<i64, i64> PII;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
vector<vector<int>> C(N + 1);
for (int i = 1; i <= N; i ++) {
int c;
cin >> c;
for (int j = 0; j < c; j ++) {
int x;
cin >> x;
C[i].push_back(x);
}
}
vector<bool> read(N + 1);
auto dfs = [&](auto self, int x) -> void{
if (read[x])
return ;
for (auto i : C[x])
self(self, i);
read[x] = true;
if (x != 1)
cout << x << ' ';
};
dfs(dfs, 1);
return 0;
}