链接:https://codeforces.com/gym/104065
A
#include "bits/stdc++.h"
using namespace std;
using i64 = long long;
constexpr int N = 2E5;
bool vis[N + 10][11][11];
int ans[N + 10][11][11];
void solve() {
for (int i = 0; i <= N + 1; i++) {
for (int j = 0; j < 11; j++) {
for (int k = 0; k < 11; k++) {
ans[i][j][k] = -1E9;
}
}
}
int n, m;
cin >> n >> m;
vector<int> a(n + 1), b(n + 1);
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
cin >> b[i];
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
function<int(int, int, int, int)> dfs = [&](int nowa, int nowb, int picka, int pickb) {
if (min(nowa, picka) == 0 && min(nowb, pickb) == 0) {
return 0;
}
if (vis[nowa + nowb][picka][pickb]) {
return ans[nowa + nowb][picka][pickb];
}
vis[nowa + nowb][picka][pickb] = 1;
if (nowa > 0 && picka > 0) {
int A = 1E9, B = 1E9;
if (nowa > 1) {
A = dfs(nowa - 2, nowb, picka - 1, pickb) + a[nowa];
}
if (nowb > 0 && pickb > 0) {
B = dfs(nowa - 1, nowb - 1, picka - 1, pickb - 1) + a[nowa] - b[nowb];
}
ans[nowa + nowb][picka][pickb] = max(ans[nowa + nowb][picka][pickb], min(A, B));
}
if (nowb > 0) {
int A = 1E9, B = 1E9;
if (nowb > 1 && pickb > 0) {
A = dfs(nowa, nowb - 2, picka, pickb - 1) - b[nowb - 1];
}
if (nowa > 0) {
B = dfs(nowa - 1, nowb - 1, picka, pickb);
}
ans[nowa + nowb][picka][pickb] = max(ans[nowa + nowb][picka][pickb], min(A, B));
}
return ans[nowa + nowb][picka][pickb];
};
int ans = dfs(n, n, m, m);
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int tt = 1;
//cin >> tt;
while (tt--) {
solve();
}
return 0;
}
C
#include "bits/stdc++.h"
using namespace std;
using i64 = long long;
void solve() {
int n;
cin >> n;
vector<vector<int>> g(n + 1);
for (int i = 0; i < n - 1; i++) {
int u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
i64 ans = 0;
for (auto nex : g[1]) {
i64 res = 0;
function<void(int, int, i64)> dfs = [&](int cur, int pre, i64 dep) {
res = max(res, dep);
for (auto nex : g[cur]) {
if (nex != pre) {
dfs(nex, cur, dep + 1);
}
}
};
dfs(nex, 1, 1);
ans += res;
}
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int tt = 1;
//cin >> tt;
while (tt--) {
solve();
}
return 0;
}
G
#include "bits/stdc++.h"
using namespace std;
using i64 = long long;
void solve() {
int n;
cin >> n;
vector<int> tmp(n);
for (int i = 0; i < n; i++) {
cin >> tmp[i];
}
int ans = 0;
int tmpn = n;
while (1) {
int SIZE = tmp.size();
if (SIZE == 1) {
break;
}
vector<int> p;
for (int i = 0; i < SIZE; i++) {
if (i == 0) {
if (tmp[i + 1] < tmp[i]) {
p.push_back(tmp[i]);
}
} else if (i == SIZE - 1) {
if (tmp[i - 1] < tmp[i]) {
p.push_back(tmp[i]);
}
} else {
if (tmp[i + 1] < tmp[i] && tmp[i - 1] < tmp[i]) {
p.push_back(tmp[i]);
}
}
}
tmp = p;
ans++;
}
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int tt = 1;
//cin >> tt;
while (tt--) {
solve();
}
return 0;
}
H
#include "bits/stdc++.h"
using namespace std;
using i64 = long long;
void solve() {
int n;
cin >> n;
n = 2 * n - 1;
cout << n << '\n';
for (int i = 1; i <= n; i++) {
cout << i << " " << i << '\n';
}
cout << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int tt = 1;
//cin >> tt;
while (tt--) {
solve();
}
return 0;
}
M
#include "bits/stdc++.h"
using namespace std;
using i64 = long long;
//constexpr int M = 998244353;
//constexpr int M = 1000000007;
void solve() {
string s;
cin >> s;
int n;
n = s.size();
auto check = [&](char ch, char ch1) {
if (ch1 == 'S' && ch == 'P') {
return 1;
}
if (ch1 == 'R' && ch == 'S') {
return 1;
}
if (ch1 == 'P' && ch == 'R') {
return 1;
}
return 0;
};
vector<int> st;
for (int i = 0; i < n; i++) {
while (!st.empty() && check(s[st.back()], s[i])) {
st.pop_back();
}
st.push_back(i);
}
cout << s[st[0]] << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cout << fixed << setprecision(6);
int tt = 1;
cin >> tt;
for (int _ = 1; _ <= tt; _++) {
solve();
}
return 0;
}
标签:Onsite,tmp,Mianyang,2022ccpc,int,nowa,nowb,picka,pickb
From: https://www.cnblogs.com/kiddingma/p/16937261.html