当前位置:网站首页>Codeworks round 809 (Div. 2) (6/6) (Kruskal reconstruction tree)
Codeworks round 809 (Div. 2) (6/6) (Kruskal reconstruction tree)
2022-07-27 07:14:00 【eyuhaobanga】
simulation
AC Code :
#include <bits/stdc++.h> using namespace std; using LL = long long; char s[100]; void Solve() { int n, m; cin >> n >> m; vector<int> a(n + 1); for (int i = 1; i <= m; i++) { s[i] = 'B'; } for (int i = 1; i <= n; i++) { cin >> a[i]; if (a[i] > m + 1 - a[i]) { if (s[m + 1 - a[i]] != 'A') { s[m + 1 - a[i]] = 'A'; } else { s[a[i]] = 'A'; } } else { if (s[a[i]] != 'A') { s[a[i]] = 'A'; } else { s[m + 1 - a[i]] = 'A'; } } } for (int i = 1; i <= m; i++) { cout << s[i]; } cout << '\n'; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while (T--) { Solve(); } return 0; }Looking for a regular , Judge parity
AC Code :
#include <bits/stdc++.h> using namespace std; using LL = long long; void Solve() { int n; cin >> n; vector<int> a(n + 1);//ji vector<int> b(n + 1);//ou vector<int> c(n + 1); for (int i = 1; i <= n; i++) { int x; cin >> x; if (a[x] == 0 && b[x] == 0) { if (i & 1) { a[x]++; } else { b[x]++; } } else { if (i & 1 && !(a[x] & 1)) { a[x]++; } else if (!(i & 1) && a[x] & 1) { a[x]++; } if (i & 1 && b[x] & 1) { b[x]++; } else if (!(i & 1) && !(b[x] & 1)) { b[x]++; } } } for (int i = 1; i <= n; i++) { cout << max(a[i], b[i]) << " \n"[i == n]; } } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while (T--) { Solve(); } return 0; }simulation , Split parity
AC Code :
#include <bits/stdc++.h> using namespace std; using LL = long long; void Solve() { int n; cin >> n; vector<int> a(n); LL sum = 0, ans = 0x3f3f3f3f; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 1; i < n - 1; i += 2) { if (a[i - 1] >= a[i] || a[i + 1] >= a[i]) { sum += max({a[i - 1] + 1, a[i], a[i + 1] + 1}) - a[i]; } } ans = sum; if (n % 2 == 0) { for (int i = n - 2; i > 0; i--) { if (i % 2 == 0) { sum += max({a[i - 1] + 1, a[i], a[i + 1] + 1}) - a[i]; } else { sum -= max({a[i - 1] + 1, a[i], a[i + 1] + 1}) - a[i]; } ans = min(ans, sum); } } cout << ans << '\n'; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while (T--) { Solve(); } return 0; }violence , mathematics , simulation
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; void Solve() { int n, k; cin >> n >> k; vector<int> a(n); rep (i, 0, n) { cin >> a[i]; } int ans = 0x3f3f3f3f; for (int i = 1; i <= a[0]; i++) { int maxx = i; rep (j, 0, n) { int p; if (a[j] / i == 0) { p = k; } else { p = min({k, a[j] / i}); } maxx = max({maxx, a[j] / p}); } ans = min({ans, maxx - i}); } cout << ans << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; rep (i, 0, T) { Solve(); } return 0; }mathematics , greedy
It is worth thinking carefully
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 a[100010], b[100010]; void Solve() { int n, k; cin >> n >> k; rep (i, 0, n) { cin >> a[i]; } memset(b, 0, sizeof(b)); int val = 1e9 + 7; for (int i = 0; i < n; i++) { for (int j = 1; j <= k && j <= a[i]; j = a[i] / (a[i] / j) + 1) { int val2 = a[i] / j; b[val2 + 1] = max(b[val2 + 1], val); val = val2; } b[0] = max(b[0], val); } int ans = 1e9 + 7, maxx = -1; for (int i = 0; i <= a[0]; i++) { maxx = max(maxx, b[i]); ans = min(ans, maxx - i); } cout << ans << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; rep (i, 0, T) { Solve(); } return 0; }Kruskal Refactoring tree + Tree analysis +LCA+ST surface
Have time to learn Kruskal Refactoring tree
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; vector<int> G[400010]; int n, m, q, tot; int f[400010], son[400010], dep[400010], siz[400010], top[400010], fa[400010], w[400010], st[400010][22], lg[400010]; void init1() { for (int i = 2; i <= 400005; i++) { lg[i] = lg[i >> 1] + 1; } } void init2() { for (int i = 1; i <= tot; i++) { G[i].clear(); fa[i] = w[i] = f[i] = son[i] = top[i] = siz[i] = 0; } } void dfs1(int u, int father) { f[u] = father; dep[u] = dep[father] + 1; siz[u] = 1; for (auto it : G[u]) { if (it == father) { continue; } dfs1(it, u); siz[u] += siz[it]; if (siz[son[u]] < siz[it]) { son[u] = it; } } } void dfs2(int u, int t) { top[u] = t; if (!son[u]) { return; } dfs2(son[u], t); for (auto it : G[u]) { if (it == f[u] || it == son[u]) { continue; } dfs2(it, it); } } int lca(int u, int v) { while (top[u] != top[v]) { if (dep[top[u]] < dep[top[v]]) { swap(u, v); } u = f[top[u]]; } return dep[u] < dep[v] ? u : v; } int getfa(int x) { return fa[x] == x ? x : fa[x] = getfa(fa[x]); } void build() { for (int i = 1; i <= tot; i++) { st[i][0] = i; } for (int i = 1; i <= 20; i++) { for (int j = 1; j + (1 << i) - 1 <= tot; j++) { st[j][i] = lca(st[j][i - 1], st[j + (1 << (i - 1))][i - 1]); } } } int query(int l, int r) { int x = lg[r - l + 1]; return w[lca(st[l][x], st[r - (1 << x) + 1][x])]; } void Solve() { cin >> n >> m >> q; iota(fa, fa + 2 * n + 2, 0); tot = n; for (int i = 1; i <= m; i++) { int u, v; cin >> u >> v; int uu = getfa(u), vv = getfa(v); if (uu == vv) { continue; } w[++tot] = i; G[tot].push_back(uu); G[uu].push_back(tot); G[vv].push_back(tot); G[tot].push_back(vv); fa[uu] = tot; fa[vv] = tot; } dfs1(tot, 0); dfs2(tot, tot); build(); rep (i, 0, q) { int l, r; cin >> l >> r; cout << query(l, r) << ' '; } cout << '\n'; init2(); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T; init1(); cin >> T; rep (i, 0, T) { Solve(); } return 0; }
边栏推荐
- Quartus:往别人的工程添加.v文件报错
- Watermelon book learning Chapter 5 --- neural network
- Analysis on the current situation and optimization strategy of customer experience management in banking industry
- DNA偶联PbSe量子点|近红外硒化铅PbSe量子点修饰脱氧核糖核酸DNA|PbSe-DNA QDs
- Gbase 8C - SQL reference 6 SQL syntax (15)
- 2021 interview question of php+go for Zhongda factory (1)
- Jest single test style problem [identity obj proxy] NPM package
- Dajiang livox customized format custommsg format conversion pointcloud2
- 指令集董事长潘爱民出席2022 ECUG Con,为中国技术力量发声
- Shell编程的规范和变量
猜你喜欢

把Excel转换成CSV/CSV UTF-8

Derivative, partial derivative and gradient

DNA modified noble metal nanoparticles | DNA modified gold nanoparticles (scientific research level)

Significance of NVIDIA SMI parameters

DDD Domain Driven Design Notes

AI:业余时间打比赛—挣它个小小目标—【阿里安全×ICDM 2022】大规模电商图上的风险商品检测比赛

基于SSM图书借阅管理系统

Pytorch uses data_ Prefetcher improves data reading speed

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

网易云信亮相 GIAC 全球互联网架构大会,解密新一代音视频架构在元宇宙场景的实践...
随机推荐
Digital image processing Chapter 1 Introduction
Working principle analysis of deepsort
Analysis of pix2pix principle
Analysis of online and offline integration mode of o2o E-commerce
Gbase 8C - SQL reference 6 SQL syntax (11)
Unittest suite and runner
Interpretation of deepsort source code (VII)
MangoDB
Student achievement management system based on SSM
基于SSM音乐网站管理系统
内部类--看这篇就懂啦~
C#时间相关操作
把Excel转换成CSV/CSV UTF-8
PNA肽核酸修饰多肽Suc-Tyr-Leu-Val-pNA|Suc-Ala-Pro-Phe-pNA 11
Why can cross entropy loss be used to characterize loss
火狐浏览器,访问腾讯云服务器的时候,出现建立安全连接失败的问题。
Analysis on the current situation and optimization strategy of customer experience management in banking industry
CdS quantum dots modified DNA | CDs DNA QDs | near infrared CdS quantum dots coupled DNA specification information
脱氧核糖核酸DNA改性近红外二区砷化镓GaAs量子点|GaAs-DNA QDs|DNA修饰GaAs量子点
DNA(脱氧核糖核酸)供应|碳纳米管载核酸-DNA/RNA材料|DNA/RNA核酸修饰磁性纳米颗粒