回头看,轻舟已过万重山.|

Ke_scholar

园龄:2年2个月粉丝:30关注:10

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;
}

本文作者:Ke_scholar

本文链接:https://www.cnblogs.com/Kescholar/p/17644986.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   Ke_scholar  阅读(89)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起