Codeforces Round 932 (Div. 2) ABCD
A. Entertainment in MAC
题意:给定字符串 \(S\),有两种操作,每次操作其中之一:
- 把 \(S\) 变为 \(S\) 的翻转 \(T\)。
- 把 \(S\) 变为 \(S + T\)。
问操作恰好 \(n\) 次能得到的最小字典序,\(n\) 为偶数。
候选字符串的前缀要么是 \(S\),要么是 \(T\),前缀相同而长度更长肯定不优,因此 \(ans = min(S, T + S)\)。
void solve() {
cin >> n >> s;
t = s;
ranges::reverse(t);
if(t < s) cout << (t + s) << '\n';
else cout << s << '\n';
}
B. Informatics in MAC
题意:给定数组 \(a\),划分为若干段(大于 \(1\) ),求一种划分方式,使得每段的 \(mex\) 相同,或者不存在。
\(mex\) 相同的两段合并后 \(mex\) 不变。
于是问题转化为:把数组分为两段,使得每段 \(mex\) 相同。
预处理前缀以及后缀 \(mex\),枚举划分位置。
void solve() {
int n; cin >> n; vector<int> a(n + 1);
rep(i, 1, n) cin >> a[i];
vector<int> pre(n + 1, 0), suf(n + 1, 0);
set<int> se;
rep(i, 0, n) se.insert(i);
rep(i, 1, n) {
if(se.find(a[i]) != end(se)) {
se.erase(a[i]);
}
pre[i] = *begin(se);
}
rep(i, 0, n) se.insert(i);
per(i, n, 1) {
if(se.find(a[i]) != end(se)) {
se.erase(a[i]);
}
suf[i] = *begin(se);
}
rep(i, 2, n) {
if(pre[i - 1] == suf[i]) {
cout << 2 << '\n';
cout << 1 << ' ' << i - 1 << '\n';
cout << i << ' ' << n << '\n';
return;
}
}
cout << -1 << '\n';
}
C. Messenger in MAC
题意:给定 \(n\) 对 \((a, b)\),选出 \(k\) 对数据并任意排列。
一个长度为 \(k\) 的排列的代价如下定义:
\]
\(p\) 为各元素在排列中的位置。
在代价不大于 \(m\) 的情况下,最大化 \(k\)。
如果我们已经确定了所选元素,如何最小化代价。
$ \sum a$ 不会随顺序变化。
对于 \(b\),可以当做遍历数轴上的 \(k\) 个点所走的路程。

可以直观的看到,对 \(b\) 排序后最优。
因此,所有数先按 \(b\) 排序。
令 \(f[i][j]\) 表示选 \(i\) 个元素,最后一个元素是 \(j\) 的最小代价。
有
\]
直接转移是 \(O(n^3)\) 的,考虑前缀 \(min\) 优化。
令
\]
所以
\]
struct Node {
int a, b;
bool operator < (const Node &o) const {
return b < o.b;
}
};
void solve() {
int n, m; cin >> n >> m;
vector<Node> t(n + 1);
rep(i, 1, n) {
cin >> t[i].a >> t[i].b;
}
sort(All(t));
vector<vector<ll>> f(n + 1, vector<ll>(n + 1, 1e18));
int ans = 0;
rep(i, 1, n) {
if(t[i].a <= m) {
ans = 1;
}
f[1][i] = min(f[1][i - 1], (ll)t[i].a - t[i].b);
}
rep(i, 2, n) {
rep(j, i, n) {
f[i][j] = f[i - 1][j - 1] + t[j].a + t[j].b;
}
rep(j, i, n) {
if(f[i][j] <= m) {
ans = i;
}
f[i][j] = min(f[i][j - 1], f[i][j] - t[j].b);
}
}
cout << ans << '\n';
}
D. Exam in MAC
题意:给定一个大小为 \(n\) 的不可重集 \(s\) 和整数 \(c\),统计满足以下所有条件的 \((x, y)\) 对数。
- \(0 \leq x \leq y \leq c\)
- \(x + y\) 不在集合内。
- \(y - x\) 不在集合内。
简单的容斥。
\(Ans = U - \{x + y \in s\} - \{y - x \in s\} + \{x + y \in s\} \cap \{y - x \in s\}\)
最后一部分的交集的充要条件为两元素奇偶性相同,直接统计即可。
void solve() {
ll n, c; cin >> n >> c;
ll ans = (c + 2) * (c + 1) / 2;
int cnt[2] = {0, 0};
rep(i, 1, n) {
int x; cin >> x;
ans -= (x / 2 + 1);
ans -= (c - x + 1);
ans += ++ cnt[x & 1];
}
cout << ans << '\n';
}
Codeforces Round 932 (Div. 2) ABCD的更多相关文章
- Codeforces Round #258 (Div. 2)[ABCD]
Codeforces Round #258 (Div. 2)[ABCD] ACM 题目地址:Codeforces Round #258 (Div. 2) A - Game With Sticks 题意 ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #268 (Div. 2) ABCD
CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...
- Codeforces Round #449 (Div. 2)ABCD
又掉分了0 0. A. Scarborough Fair time limit per test 2 seconds memory limit per test 256 megabytes input ...
- Codeforces Round #143 (Div. 2) (ABCD 思维场)
题目连链接:http://codeforces.com/contest/231 A. Team time limit per test:2 seconds memory limit per test: ...
- Codeforces Round #248 (Div. 2) (ABCD解决问题的方法)
比赛链接:http://codeforces.com/contest/433 A. Kitahara Haruki's Gift time limit per test:1 second memory ...
- Codeforces Round #427 (Div. 2)——ABCD
http://codeforces.com/contest/835 A.拼英语水平和手速的签到题 #include <bits/stdc++.h> using namespace std; ...
- Codeforces Round #412 (Div. 2)ABCD
tourist的剧毒contest,题干长到让人不想做... A.看不太懂题意直接看下面input output note n组里有两数不一样的一组就rated 否则单调不增为maybe,否则unra ...
- Codeforces Round #315 (Div. 2) (ABCD题解)
比赛链接:http://codeforces.com/contest/569 A. Music time limit per test:2 seconds memory limit per test: ...
- Codeforces Round #352 (Div. 2) ABCD
Problems # Name A Summer Camp standard input/output 1 s, 256 MB x3197 B Different is Good ...
随机推荐
- el-select的简单封装,使其返回值中包含key,value,obj 三种值
常规的el-select中change事件返回值,只有key返回,业务上有些需求有需要获取到value值,所以简单的封装了一下,使返回中包含key,value,obj三个值,基本上可以满足大部分的需求 ...
- C# 平台调用过程
(1)调用LoadLibrary加载非托管DLL到内存中,并调用GetProcAddress 获得内存中非托管函数的指针. (2) 为包含非托管函数地址的托管签名生成一个DllImport存根(st ...
- 使用vott对车牌位置进行标注
1.软件安装 vott 下载地址 https://github.com/microsoft/VoTT/releases 双击vott-2.2.0-win32.exe安装标注软件,安装成功后桌面会生成应 ...
- 解密数仓的SQL ON ANYWHERE技术
本文分享自华为云社区<GaussDB DWS的SQL ON ANYWHERE技术解密>,作者:tooooooooooomy. 1. 前言 适用版本:[8.1.1(及以上)] 查询分析是大数 ...
- #莫比乌斯反演,欧拉函数#洛谷 5518 [MtOI2019]幽灵乐团
题目传送门 分析 前置知识:\(\sum_{d|n}\mu(d)=[n==1]\),\(\sum_{d|n}\mu(d)\frac{n}{d}=\varphi(n)\) 把最小公倍数拆开可以得到 \[ ...
- java中DelayQueue的使用
目录 简介 DelayQueue DelayQueue的应用 总结 java中DelayQueue的使用 简介 今天给大家介绍一下DelayQueue,DelayQueue是BlockingQueue ...
- winrt新dx截图最小实现
转自:https://stackoverflow.co/questions/11283015 效果还是很不错的 #include <iostream> #include <Windo ...
- 【译】如何在 Visual Studio 中安装 GitHub Copilot
GitHub Copilot 简介 GitHub Copilot 是一个新工具,可以帮助您在人工智能的帮助下更快,更智能地编写代码.它可以建议代码补全,生成代码片段,甚至为您编写整个函数.GitHub ...
- 手把手教你使用ArkTS中的canvas实现签名板功能
一.屏幕旋转 ● 实现签名板的第一个功能就是旋转屏幕.旋转屏幕在各种框架中都有不一样的方式,比如:在H5端,我们一般是使用CSS中的transform属性中的rotate()方法来强制将网页横屏, ...
- HarmonyOS实现几种常见图片点击效果
一. 样例介绍 HarmonyOS提供了常用的图片.图片帧动画播放器组件,开发者可以根据实际场景和开发需求,实现不同的界面交互效果,包括:点击阴影效果.点击切换状态.点击动画效果.点击切换动效. 相关 ...