Codeforces Good Bye 2023
A. 2023
正常签到。
void solve() {
int n, k, ok = 1;
cin >> n >> k;
int t = 2023;
while(n --) {
int x;
cin >> x;
if(t % x) ok = 0;
t /= x;
}
cout << (ok ? "YES\n" : "NO\n");
if(ok) {
cout << t << ' ';
for(int i = 1; i < k; ++ i) cout << '1' << ' ';
cout << '\n';
}
}
B. Two Divisors
情况一:\(b \bmod a \neq 0\),答案为 \(lcm(a, b)\)。
情况二:\(b \bmod a = 0\),则答案为 \(p \cdot lcm = p \cdot b\),\(p\) 为一个小于 \(a\) 的质数。
由于题目保证 \(a, b\) 是最大两个因子,因此 \(\dfrac{b}{a}\) 为一个小于 \(a\) 的质数。
所以满足题意的一个答案为 \(\dfrac{b}{a} \cdot b\)。
void solve() {
ll a, b;
scanf("%lld%lld", &a, &b);
printf("%lld\n", b % a == 0 ? b / a * b : lcm(a, b));
}
C. Training Before the Olympiad
简化题面:在数组中选两个数,将这两个数合并为 \(\lfloor\dfrac{a[i]+a[j]}{2}\rfloor \times 2\),求在最优操作下,最后剩下数是什么。
先手要使最后结果尽可能大,后手要使最后结果尽可能小。
- 最终答案最大为 $ \sum a[i]$
- 操作后的整个数一定是偶数。
- 后手可以通过选取一奇一偶使答案减一。
现在思路就非常清晰了。
情况一:当前数组中奇数的数量为 \(1\),那么先手必选两个偶数,后手必选这个奇数。
情况二:当前数组中奇数的数量为 \(2\),那么先手必选这两个奇数,后手不能使答案变小。
情况三:当前数组中奇数的数量为 \(3\),那么先手必选两个奇数,后手必选剩下的一个奇数。
由此我们可以发现答案与奇数个数 \(\bmod 3\) 有关。
void solve() {
int n;
cin >> n;
vector<ll> a(n + 1, 0), b(n + 1, 0);
for(int i = 1; i <= n; ++ i) cin >> a[i], b[i] = b[i - 1] + (a[i] % 2), a[i] += a[i - 1];
cout << a[1] << ' ';
for(int i = 2; i <= n; ++ i) {
cout << a[i] - b[i] / 3 - (b[i] % 3 == 1) << ' ';
}
cout << '\n';
}
D. Mathematical Problem
- 我们要构造的是 \(\lceil \dfrac{n}{2} \rceil\) 位数的平方。
- \((1 \ldots 3 \ldots)^2\) 一定是 \((1 \ldots 6\ldots9 \ldots)^2\)
- \((3 \ldots 1 \ldots)^2\) 一定是 \((9 \ldots 6\ldots1 \ldots)^2\)
- \((14 \ldots)^2)\) 一定是 \((196 \ldots)\)
发现上述三种情况很好地契合本题要求。
现在检验这些情况的数目是否 \(\ge n\)。
情况一:以 \(1\) 为首元素枚举后面的位置,共 \(\lfloor \dfrac{n}{2} \rfloor\) 种。
情况一:以 \(3\) 为首元素枚举后面的位置,共 \(\lfloor \dfrac{n}{2} \rfloor\) 种。
情况一:共 \(1\) 种。
加起来共 \(n\) 种,非常完美。
void solve() {
int n, cnt = 0;
cin >> n;
if(n == 1) cout << "1\n";
else {
int len = n / 2 + 1;
for(int i = 0; i < len - 1; ++ i) {
cout << '1';
for(int j = 0; j < i; ++ j) cout << '0';
cout << '6';
for(int j = 0; j < i; ++ j) cout << '0';
cout << '9';
for(int j = 1; j < n - 2 - i * 2; ++ j) cout << '0';
cout << '\n';
}
for(int i = 0; i < len - 1; ++ i) {
cout << '9';
for(int j = 0; j < i; ++ j) cout << '0';
cout << '6';
for(int j = 0; j < i; ++ j) cout << '0';
cout << '1';
for(int j = 1; j < n - 2 - i * 2; ++ j) cout << '0';
cout << '\n';
}
cout << "196";
for(int i = 0; i < n - 3; ++ i) cout << '0';
cout << '\n';
}
}
E. Happy Life in University
int val[N << 2], tag[N << 2];
void build(int x, int l, int r) {
val[x] = tag[x] = 0;
if(l == r) return;
int mid = l + r >> 1;
build(x << 1, l, mid), build(x << 1 | 1, mid + 1, r);
}
void pushup(int x) {
val[x] = max(val[x << 1], val[x << 1 | 1]);
}
void pushdown(int x) {
tag[x << 1] += tag[x], tag[x << 1 | 1] += tag[x];
val[x << 1] += tag[x], val[x << 1 | 1] += tag[x];
tag[x] = 0;
}
void modify(int x, int l, int r, int a, int b, int delta) {
if(a <= l && r <= b) {
tag[x] += delta;
val[x] += delta;
return;
}
pushdown(x);
int mid = l + r >> 1;
if(mid >= a) modify(x << 1, l, mid, a, b, delta);
if(mid < b) modify(x << 1 | 1, mid + 1, r, a, b, delta);
pushup(x);
}
int query(int x, int l, int r, int a, int b) {
if(a <= l && r <= b) return val[x];
pushdown(x);
int mid = l + r >> 1, ret = 1;
if(mid >= a) ret = max(ret, query(x << 1, l, mid, a, b));
if(mid < b) ret = max(ret, query(x << 1 | 1, mid + 1, r, a, b));
return ret;
}
long long ans;
int n, a[N];
int dfn[N], out[N], timestamp;
int lst[N]; //在x的祖先中离x最近的颜色相同的点
vector<int> G[N], e[N]; //e为在x子树中离x最近的颜色相同的点
void dfs(int x) { //枚举lca
dfn[x] = ++ timestamp;
if(lst[a[x]]) e[lst[a[x]]].push_back(x);
int tmp = lst[a[x]];
lst[a[x]] = x;
for(auto y : G[x]) dfs(y);
lst[a[x]] = tmp; //还原last
out[x] = timestamp; //[dfn[x], out[x]]为整棵子树对应序列
modify(1, 1, n, dfn[x], out[x], 1);
for(auto y : e[x]) modify(1, 1, n, dfn[y], out[y], -1);
int mx = 1;
for(auto y : G[x]) {
int t = query(1, 1, n, dfn[y], out[y]);
ans = max(ans, 1ll * mx * t);
mx = max(mx, t);
}
}
void solve() {
cin >> n;
for(int i = 1; i <= n; ++ i) G[i].clear(), e[i].clear();
for(int i = 2, p; i <= n; ++ i) {
cin >> p;
G[p].push_back(i);
}
for(int i = 1; i <= n; ++ i) cin >> a[i];
build(1, 1, n);
ans = 1, timestamp = 0, dfs(1);
cout << ans << '\n';
}
F. Group Division
void Tarjan(int x) {
dfn[x] = low[x] = ++ timestamp;
int cnt = 0;
for(int y : G[x]) {
if(!cs[y]) {
if(!dfn[y]) {
Tarjan(y);
low[x] = min(low[x], low[y]);
if(low[y] >= dfn[x]) {
if(x != root || ++ cnt > 1) cut[x] = true;
}
}
else low[x] = min(low[x], dfn[y]);
}
}
}
void clear_part() {
for(int i = 1; i <= n; ++ i) {
dfn[i] = low[i] = cut[i] = 0;
}
timestamp = 0;
}
void clear_all() {
for(int i = 1; i <= n; ++ i) {
dfn[i] = low[i] = cut[i] = cs[i] = 0;
G[i].clear();
}
timestamp = 0;
}
void solve() {
cin >> n1 >> n2 >> m;
n = n1 + n2;
for(int i = 1; i <= m; ++ i) {
int x, y;
cin >> x >> y;
G[x].push_back(y);
G[y].push_back(x);
}
for(int T = 1; T <= n1; ++ T) {
for(int i = 1; i <= n; ++ i) {
if(!cs[i]) {
Tarjan(root = i);
break;
}
}
for(int i = 1; i <= n; ++ i) {
if(!cs[i] && !cut[i]) {
bool ok = false;
for(int y : G[i]) ok |= cs[y];
if(ok || T == 1) {
cs[i] = 1;
break;
}
}
}
clear_part();
}
for(int i = 1; i <= n; ++ i) if(cs[i]) cout << i << ' '; cout << '\n';
for(int i = 1; i <= n; ++ i) if(!cs[i]) cout << i << ' '; cout << '\n';
clear_all();
}
Codeforces Good Bye 2023的更多相关文章
- codeforces Good bye 2016 E 线段树维护dp区间合并
codeforces Good bye 2016 E 线段树维护dp区间合并 题目大意:给你一个字符串,范围为‘0’~'9',定义一个ugly的串,即串中的子串不能有2016,但是一定要有2017,问 ...
- Codeforces:Good Bye 2018(题解)
Good Bye 2018! 题目链接:https://codeforces.com/contest/1091 A. New Year and the Christmas Ornament 题意: 给 ...
- codeforces Good Bye 2015 B. New Year and Old Property
题目链接:http://codeforces.com/problemset/problem/611/B 题目意思:就是在 [a, b] 这个范围内(1 ≤ a ≤ b ≤ 10^18)统计出符合二进制 ...
- Codeforces Good Bye 2015 D. New Year and Ancient Prophecy 后缀数组 树状数组 dp
D. New Year and Ancient Prophecy 题目连接: http://www.codeforces.com/contest/611/problem/C Description L ...
- Codeforces Good Bye 2015 C. New Year and Domino 前缀和
C. New Year and Domino 题目连接: http://www.codeforces.com/contest/611/problem/C Description They say &q ...
- Codeforces Good bye 2015 B. New Year and Old Property dfs 数位DP
B. New Year and Old Property 题目连接: http://www.codeforces.com/contest/611/problem/B Description The y ...
- Codeforces Good Bye 2015 A. New Year and Days 水题
A. New Year and Days 题目连接: http://www.codeforces.com/contest/611/problem/A Description Today is Wedn ...
- codeforces Good Bye 2013 379D New Year Letter
题目链接:http://codeforces.com/problemset/problem/379/D [题目大意] 告诉你初始字符串S1.S2的长度和递推次数k, 使用类似斐波纳契数列的字符串合并的 ...
- Codeforces Good Bye 2016 题解
好久没有fst题了...比赛先A了前4题然后发现room里有人已经X完题了没办法只能去打E题,结果差一点点打完...然后C题fst掉了结果就掉rating 了...下面放题解 ### [A. New ...
- Codeforces Good Bye 2018
咕bye 2018,因为我这场又咕咕咕了 无谓地感慨一句:时间过得真快啊(有毒 A.New Year and the Christmas Ornament 分类讨论后等差数列求和 又在凑字数了 #in ...
随机推荐
- 以最大速度将数据迁移至AWS S3存储
数据上云,已经成为企业数据管理发展的必然趋势. 对于企业而言,数据上云"常态化"的趋势,无疑是一个巨大的技术红利.而数据规模爆发式增长的今天,移动和访问云端数据却成为困扰企业的一大 ...
- KingbaseESV8R6表空间与数据库,模式,表的关系
自定义表空间的作用 使用多个表空间可以更灵活地执行数据库操作.当数据库具有多个表空间时,您可以: 1.将用户数据与系统表数据分开存储在不同性能的存储上,以减少I/O争用. 2.将一个应用程序的数据与另 ...
- Spark技术生态
Spark的技术生态 Spark的技术生态包含了各种丰富的组件,而不同的组件提供了不同功能,以适应不同场景. Spark core spark core包含Spark的基本功能,定义了RDD的API以 ...
- 20 JavaScript和HTML交互
20 JavaScript和HTML交互 在HTML中可以直接在标签上给出一些事件的触发. 例如, 页面上的一个按钮. <input type="button" value= ...
- Vue3 Diff 之 patchKeyedChildren 动态示例
在学习全网学习各路大神的关于Vue3 Diff算法分析文章的时候,一定离不开关键方法 patchKeyedChildren. patchKeyedChildren 处理的场景比较多,大致有 5 个主要 ...
- OpenHarmony创新赛 | 赛事宣讲会日期重磅官宣!为你带来超详尽的赛事攻略
最近接到很多小伙伴私信提问,比如如何报名开放原子开源大赛OpenAtom OpenHarmony(简称:"OpenHarmony")创新赛?有哪些赛题可以报名参赛?现在,赛事宣 ...
- MyBatis resultMap中collection过滤空字段
在使用MyBatis查询数据时,返回值可以定义为resultMap. 如果返回的对象中有列表,还可以使用collection标签进行定义. 此时,如果不想某些字段为空的数据加入列表,可以使用notNu ...
- 用于多视角人群计数的协同通信图卷积网络 Co-Communication Graph Convolutional Network for Multi-View Crowd Counting
Multi-Camara Methods Co-Communication Graph Convolutional Network for Multi-View Crowd Counting 论文ur ...
- HarmonyOS实践之应用状态变量共享
平时在开发的过程中,我们会在应用中共享数据,在不同的页面间共享信息.虽然常用的共享信息,也可以通过不同页面中组件间信息共享的方式,但有时使用应用级别的状态管理会让开发工作变得简单. 根据不同的使用 ...
- c# 反编译对比(旧)
前言 旧的都是我以前博客的迁移. 我们写代码有时候遇到一些问题,或者我们想优化我们的代码,我们想要看编译后的运行情况,那么反编译是必须要做的一件事. 正文 在此我自己使用的是reflector和ILS ...