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 ...
随机推荐
- C# 使用AForge调用摄像头
AForge官网地址:http://www.aforgenet.com/framework/ using System; using System.Collections.Generic; using ...
- kingbaseES坏块修复功能
1.自动坏块修复简介 主数据库访问系统表数据.索引.持久化用户表数据.索引时,从磁盘读取数据块至共享缓冲区,如果检测到坏块,自动从备节点获取坏块的副本,并修复坏块. 坏块修复相关参数 参数名称 默认值 ...
- 金仓数据库kbcrypto 插件实现sm加密算法
首先介绍一下sm4 算法 SM4 算法是对称加密算法,国标 GB/T 32907 对 SM4 对称加密算法进行了详细描述.SM4 算法密钥长度固定为128bit,加密解密采用相同的密钥,加解密速度较快 ...
- 01 jQuery初使用
01 jQuery初使用 jQuery是一个曾经火遍大江南北的一个Javascript的第三方库. jQuery的理念: write less do more. 其含义就是让前端程序员从繁琐的js代码 ...
- 7 CSS选择器优先级
7 选择器优先级 所谓CSS优先级,即是指CSS样式在浏览器中被解析的先后顺序.样式表中的特殊性描述了不同规则的相对权重. /* !important > 行内样式>ID选择器 > ...
- Docker学习路线13:部署容器
部署容器是使用Docker和容器化管理应用程序更高效.易于扩展和确保跨环境一致性性能的关键步骤.本主题将为您概述如何部署Docker容器以创建和运行应用程序. 概述 Docker容器是轻量级.可移植且 ...
- MySQL 8.0字符集校正
MySQL升级为8.0版本时,之前版本的字符集往往是不同的,需要校正. 执行下面的三个SQL语句的查询结果,可以从库.表.列三个层面对字符集进行校正. 库 select concat('alter d ...
- configparser封装后报错:configparser.NoSectionError: No section: 'LoginElement'
前言 这是目录结构 先贴一下源代码 # read_ini.pyimport configparser class ReadIni(): """读取 ini.ini 配置文 ...
- java集合源码详解
一 Collection接口 1.List 1.1ArrayList 特点 1.底层实现基于动态数组,数组特点根据下表查找元素速度所以查找速度较快.继承自接口 Collection ->Lis ...
- Linux之parted
[摘要] parted用于对磁盘(或RAID磁盘)进行分区及管理,与fdisk分区工具相比,支持2TB以上的磁盘分区,并且允许调整分区的大小. 使用它你可以创建.清除.调整.移动和复制ext2.ext ...