链接:https://codeforces.com/gym/104459
A
#include "bits/stdc++.h"
using namespace std;
using i64 = long long;
string S[] = {
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday"
};
void solve() {
int y1, m1, d1;
string s;
cin >> y1 >> m1 >> d1 >> s;
int i = 0;
while (s != S[i]) {
i++;
}
int y2, m2, d2;
cin >> y2 >> m2 >> d2;
i64 j = i + (y2 - y1) * 360LL + (m2 - m1) * 30LL + (d2 - d1);
j %= 5;
j += 5;
j %= 5;
cout << S[j] << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
C
#include "bits/stdc++.h"
using namespace std;
using i64 = long long;
void solve() {
int n, k;
cin >> n >> k;
string s;
cin >> s;
int x = 0, y = 0;
vector<pair<int, int>> a(n);
i64 ans = 0;
for (int i = 0; i < n; i++) {
if (s[i] == 'U') {
y++;
} else if (s[i] == 'D') {
y--;
} else if (s[i] == 'L') {
x--;
} else {
x++;
}
a[i] = {x, y};
ans = max(ans, 1LL * abs(x) + abs(y));
}
auto &[X, Y] = a[n - 1];
for (int i = 0; i < n; i++) {
auto &[x, y] = a[i];
ans = max(ans, abs(1LL * (k - 1) * X + x) + abs(1LL * (k - 1) * Y + y));
}
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
D. Game on a Graph
#include "bits/stdc++.h"
using namespace std;
using i64 = long long;
void solve() {
int k;
string s;
cin >> k >> s;
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
}
int cnt = m - (n - 1);
cout << 3 - (s[cnt % k] - '0') << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
F. Stones in the Bucket
#include "bits/stdc++.h"
using namespace std;
using i64 = long long;
void solve() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
i64 sum = accumulate(a.begin(), a.end(), 0LL);
i64 ave = sum / n;
i64 ans = 0;
for (int i = 0; i < n; i++) {
if (a[i] > ave) {
ans += a[i] - ave;
}
}
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
L. Median
#include "bits/stdc++.h"
using namespace std;
using i64 = long long;
void solve() {
int n, m;
cin >> n >> m;
vector<vector<int>> g(n), rg(n);
vector<int> deg(n), rdeg(n);
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
u--, v--;
g[u].push_back(v);
rg[v].push_back(u);
deg[v]++;
rdeg[u]++;
}
vector<bitset<101>> f(n), rf(n);
auto bfs = [&](const vector<vector<int>> &g, vector<int> °,
vector<bitset<101>> &f) {
queue<int> q;
for (int i = 0; i < n; i++) {
if (!deg[i]) {
q.push(i);
}
}
int tot = 0;
while (!q.empty()) {
auto cur = q.front();
q.pop();
tot++;
for (auto &nex : g[cur]) {
if (!--deg[nex]) {
q.push(nex);
}
f[nex][cur] = 1;
f[nex] |= f[cur];
}
}
return tot;
};
int tot = bfs(g, deg, f);
if (tot != n) {
cout << string(n, '0') << '\n';
return;
}
bfs(rg, rdeg, rf);
int k = n / 2;
for (int i = 0; i < n; i++) {
int l = f[i].count();
int r = rf[i].count();
if (l <= k && r <= k) {
cout << 1;
} else {
cout << 0;
}
}
cout << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
M. Sekiro
#include "bits/stdc++.h"
using namespace std;
using i64 = long long;
void solve() {
int n, k;
cin >> n >> k;
for (int i = 0; i < k; i++) {
n = (n + 1) / 2;
if (n == 0 || n == 1) {
break;
}
}
cout << n << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
标签:std,Provincial,Shandong,Contest,int,cin,long,++,using
From: https://www.cnblogs.com/kiddingma/p/17679262.html