链接:https://codeforces.com/gym/104025
A. Gifts in box
#include "bits/stdc++.h"
using namespace std;
using i64 = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m, h;
cin >> n >> m >> h;
vector<vector<int>> a(n, vector<int>(m));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> a[i][j];
}
}
vector<vector<int>> b(h, vector<int>(m));
for (int i = 0; i < h; i++) {
for (int j = 0; j < m; j++) {
for (int k = 0; k < n; k++) {
if (a[k][j] >= i + 1) {
b[i][j]++;
}
}
}
}
for (int i = 0; i < h; i++) {
for (int j = 0; j < m; j++) {
cout << b[i][j] << " \n"[j == m - 1];
}
}
return 0;
}
B. BIT Palindrome
#include "bits/stdc++.h"
using namespace std;
using i64 = long long;
constexpr int P = 1000000007;
void solve() {
int n;
cin >> n;
if (n == 1) {
cout << "0\n";
} else if (n == 2) {
cout << "3\n";
} else if (n == 3) {
cout << "18\n";
} else {
cout << 6LL * (n + 1) % P << '\n';
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
E. Equal
#include "bits/stdc++.h"
using namespace std;
using i64 = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int x, y;
cin >> x >> y;
if (y >= x) {
cout << y - x << '\n';
} else {
if (y % 2 == x % 2) {
cout << (x - y) / 2 << '\n';
} else {
cout << (x + 1 - y) / 2 + 1 << '\n';
}
}
return 0;
}
G. Get off work
#include "bits/stdc++.h"
using namespace std;
using i64 = long long;
void solve() {
int n, k;
cin >> n >> k;
vector<vector<int>> g(n);
vector<int> f(n);
for (int i = 1; i < n; i++) {
int u, v;
cin >> u >> v;
u--, v--;
g[u].push_back(v);
g[v].push_back(u);
}
int ans = 0;
function<void(int, int)> dfs = [&](int cur, int pre) {
for (auto &nex : g[cur]) {
if (nex != pre) {
dfs(nex, cur);
f[cur] += f[nex];
}
}
if (cur) {
f[cur]--;
while (f[cur] < 0) {
f[cur] += k;
ans++;
}
}
};
dfs(0, -1);
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
H. Happiness Index
#include "bits/stdc++.h"
using namespace std;
using i64 = long long;
#include "ext/pb_ds/assoc_container.hpp"
template <typename Key, typename Cmp_Fn = std::less<Key>>
class Set : public __gnu_pbds::tree<Key, __gnu_pbds::null_type, Cmp_Fn,
__gnu_pbds::rb_tree_tag,
__gnu_pbds::tree_order_statistics_node_update> {};
void solve() {
int n, k;
cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
auto f = [&](int x) {
Set<pair<i64, int>> s;
vector<i64> sum(n + 1);
i64 res = 0;
for (int i = 0; i <= n; i++) {
if (i != n) {
sum[i + 1] = sum[i] + a[i] - x;
}
res += s.order_of_key({sum[i] + 1, 0});
s.insert({sum[i], i});
}
return res;
};
cout << f(k) - f(k + 1) << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
J. Stones
#include "bits/stdc++.h"
using namespace std;
using i64 = long long;
int sg(int x) {
if (!x) {
return 0;
}
if (x & 1) {
return (x + 1) / 2;
}
return sg(x / 2 - 1);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int ans = 0;
for (int i = 0; i < n; i++) {
ans ^= sg(a[i]);
}
cout << (ans ? "Alice" : "Bob") << '\n';
return 0;
}
K. ZYW with tutors
#include "bits/stdc++.h"
using namespace std;
using i64 = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << "0\n";
return 0;
}
标签:Onsite,std,16,int,Contest,cin,long,++,using
From: https://www.cnblogs.com/kiddingma/p/17685591.html