当前位置:网站首页>Codeforces Round #787 (Div. 3)(7/7)
Codeforces Round #787 (Div. 3)(7/7)
2022-07-27 07:14:00 【eyuhaobanga】
AC Code :
#include <bits/stdc++.h> using namespace std; using i64 = long long; void solve() { int a, b, c, x, y; cin >> a >> b >> c >> x >> y; if (a + c >= x && b + c >= y && a + b + c >= x + y) { cout << "YES\n"; } else { cout << "NO\n"; } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t--) { solve(); } return 0; }AC Code :
#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]; } int ans = 0; for (int i = n - 2; i >= 0; i--) { if (a[i + 1] == 0) { cout << "-1\n"; return; } while (a[i] >= a[i + 1]) { a[i] >>= 1; ans++; } } cout << ans << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t--) { solve(); } return 0; }AC Code :
#include <bits/stdc++.h> using namespace std; using i64 = long long; void solve() { string s; cin >> s; int len = s.size(); int now = -1; for (int i = 0; i < len; i++) { if (s[i] == '1' || s[i] == '?') { now = i; } else { break; } } int ans = 0; for (int i = len - 1; i >= 0; i--) { if (now >= i - 1) { ans++; } if (s[i] == '0' || s[i] == '?') { } else { break; } } cout << ans << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t--) { solve(); } return 0; }AC Code :
#include <bits/stdc++.h> using namespace std; using i64 = long long; int n; int p[200010]; int cnt; bool vis[200010], vis1[200010]; void solve() { cin >> n; for (int i = 1; i <= n; i++) { vis[i] = false; vis1[i] = false; } for (int i = 1; i <= n; i++) { cin >> p[i]; vis1[p[i]] = true; } if (n == 1) { cout << "1\n1\n1\n\n"; return; } cnt = 0; for (int i = 1; i <= n; i++) { if (!vis1[i]) { cnt++; } } cout << cnt << '\n'; for (int i = 1; i <= n; i++) { if (vis1[i]) { continue; } vector<int> ans; int j = i; while (!vis[j]) { ans.push_back(j); vis[j] = true; j = p[j]; } cout << ans.size() << '\n'; reverse(ans.begin(), ans.end()); for (auto it : ans) { cout << it << " "; } cout << "\n"; } cout << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t--) { solve(); } return 0; }AC Code :
#include <bits/stdc++.h> using namespace std; using i64 = long long; void solve() { int n, k; cin >> n >> k; string s; cin >> s; int maxx = 0; for (int i = 0; i < n; i++) { if (s[i] - 'a' > k) { char l = s[i] - (k - maxx); char r = s[i]; for (int j = 0; j < n; j++) { if (s[j] >= l && s[j] <= r) { s[j] = l; } } break; } maxx = max(maxx, s[i] - 'a'); } for (int i = 0; i < n; i++) { if (s[i] <= maxx + 'a') { s[i] = 'a'; } } cout << s << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t--) { solve(); } return 0; }AC Code :
#include <bits/stdc++.h> using namespace std; using i64 = long long; int n, k, ans, x, y, a[200010], vis[200010], deep[200010]; vector<int> edge[200010]; int dfs(int root, int dep, int fa) { deep[root] = dep; int num = vis[root]; for (auto it : edge[root]) { if (it != fa && dfs(it, dep + 1, root)) { ans += 2; num++; } } return num; } void Solve() { cin >> n >> k; cin >> x >> y; ans = 0; for (int i = 1; i <= n; i++) { edge[i].clear(); vis[i] = 0; deep[i] = 0; } for (int i = 1; i <= k; i++) { cin >> a[i]; vis[a[i]] = 1; } vis[y] = 1; for (int i = 1; i < n; i++) { int u, v; cin >> u >> v; edge[u].push_back(v); edge[v].push_back(u); } dfs(x, 0, 0); cout << ans - deep[y] << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(0); int T; cin >> T; while (T--) { Solve(); } return 0; }AC Code :
#include <bits/stdc++.h> #define rep(i,a,n) for(int i=a;i<n;i++) using namespace std; using LL = long long; int dp[255][255][255]; //dp[i][j+k][k]=min(dp[i][j+k][k],sum[i]-j-k+dp[i-1][j][p]) int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; vector<int> a(n + 1); vector<int> sum(n + 1); for (int i = 1; i <= n; i++) { cin >> a[i]; } reverse(a.begin() + 1, a.end()); for (int i = 1; i <= n; i++) { sum[i] = sum[i - 1] + a[i]; } memset(dp, 0x3f, sizeof(dp)); dp[0][0][0] = 0; for (int i = 1; i <= n; i++) { rep (j, 0, m + 1) { int minn = 0x3f3f3f3f; rep (k, 0, m + 1) { if (j + k <= m) { minn = min(minn, dp[i - 1][j][k]); dp[i][j + k][k] = min(dp[i][j + k][k], minn + abs(sum[i] - j - k)); } } } } int ans = 0x3f3f3f3f; rep (i, 0, m + 1) { ans = min(ans, dp[n][m][i]); } cout << ans << '\n'; return 0; }The resistance and long
边栏推荐
- 网易云信亮相 GIAC 全球互联网架构大会,解密新一代音视频架构在元宇宙场景的实践...
- The vscode run command reported an error: the mark "&" is not a valid statement separator in this version.
- AI: play games in your spare time - earn it a small goal - [Alibaba security × ICDM 2022] large scale e-commerce map of risk commodity inspection competition
- pre-commit install 时 CalledProcessError
- Derivative, partial derivative and gradient
- Brief introduction of simulation model
- Codeforces Round #787 (Div. 3)(7/7)
- DNA科研实验应用|环糊精修饰核酸CD-RNA/DNA|环糊精核酸探针/量子点核酸探针
- Book borrowing management system based on SSM
- Web configuration software for industrial control is more efficient than configuration software
猜你喜欢

Qi Yue: thiol modified oligodna | DNA modified cdte/cds core-shell quantum dots | DNA coupled indium arsenide InAs quantum dots InAs DNA QDs

DNA(脱氧核糖核酸)供应|碳纳米管载核酸-DNA/RNA材料|DNA/RNA核酸修饰磁性纳米颗粒

Student achievement management system based on SSM

jest单测样式问题【identity-obj-proxy】npm包

把Excel转换成CSV/CSV UTF-8

从技术原理看元宇宙的可能性:Omniverse如何“造”火星

Norms of vectors and matrices

newest! SASAC releases new measures for digital transformation of state-owned enterprises

Matlab drawing (ultra detailed)

最新!国资委发布国有企业数字化转型新举措
随机推荐
Bert and RESNET can also be trained on mobile phones?!
如何借助自动化工具落地DevOps|含低代码与DevOps应用实践
Campus news release management system based on SSM
Day012 application of one-dimensional array
含有偶氮苯单体的肽核酸寡聚体(NH2-TNT4,N-PNAs)齐岳生物定制
基于SSM音乐网站管理系统
OpenGL development with QT (I) drawing plane graphics
vscode运行命令报错:标记“&&”不是此版本中的有效语句分隔符。
Error in running code: libboost_ filesystem.so.1.58.0: cannot open shared object file: No such file or directory
MangoDB
仿真模型简单介绍
Ci framework learning of PHP
Reflection on pytorch back propagation
Variance and covariance
Misunderstanding of slice slice in golang
Digital image processing Chapter 1 Introduction
Digital image processing -- Chapter 3 gray scale transformation and spatial filtering
Interpretation of deepsort source code (VII)
jest单测样式问题【identity-obj-proxy】npm包
Interpretation of deepsort source code (I)