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 ...
随机推荐
- ARM和x86比较
信不信,随便逮住一个人问他知不知道CPU,我想他的答案一定会是肯定的,但是如果你再问他知道ARM和X86架构么?这两者的区别又是什么?绝大多数的人肯定是一脸懵逼.今天小编就带你深入了解CPU的这两大架 ...
- salesforce零基础学习(一百三十五)项目中的零碎知识点小总结(七)
本篇参考: https://trailhead.salesforce.com/content/learn/modules/flow-implementation-2/debug-flows-as-an ...
- KingbaseES角色和权限介绍
KingbaseES 使用角色的概念管理数据库访问权限.为了方便权限管理,用户可以建立多个角色,对角色进行授权和权限回收,并把角色授予其他用户. 数据库初始化时,会创建一个超级用户的角色:system ...
- KingbaseES V8R6集群部署案例之---脚本部署节点环境检查故障
KingbaseES V8R6集群部署案例之---脚本部署节点环境检查故障 案例说明: KingbaseES V8R6集群在部署前会对集群节点系统环境进行检测,检测失败后,将中断部署:其中一个检测项, ...
- Scala 可变集合 mutable.Set
1 package chapter07 2 3 import scala.collection.mutable 4 5 object Test07_MutableSet { 6 def main(ar ...
- Android相对布局(来自菜鸟教程)
- Advanced .Net Debugging 6:程序集加载器
一.简介 这是我的<Advanced .Net Debugging>这个系列的第六篇文章.这篇文章的内容是原书的第二部分的[调试实战]的第四章.这章主要讲的是程序集加载器,比如:CLR 加 ...
- Spring内存马分析
环境搭建 踩了很多坑....,不过还好最后还是成功了 IDEA直接新建javaEE项目,然后记得把index.jsp删了,不然DispatcherServlet会失效 导入依赖: <depend ...
- 算法小白刷了一周 LeetCode 后的思考
Hi,我是 itchao 我自己工作有 2 两年多的前端开发经验,但是数据结构与算法一直不好,基本就是一个算法小白的水平. 听说大公司面试都要手写算法题,最近为了以后能去更好的公司,然后其实心里比较着 ...
- .NET Emit 入门教程:第六部分:IL 指令:7:详解 ILGenerator 指令方法:分支条件指令
前言: 经过前面几篇的学习,我们了解到指令的大概分类,如: 参数加载指令,该加载指令以 Ld 开头,将参数加载到栈中,以便于后续执行操作命令. 参数存储指令,其指令以 St 开头,将栈中的数据,存储到 ...