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\) 的排列的代价如下定义:

\[\sum_{i=1}^{k} a_{p_i} + \sum_{i=1}^{k - 1} |b_{p_i} - b_{p_{i+1}}|
\]

\(p\) 为各元素在排列中的位置。

在代价不大于 \(m\) 的情况下,最大化 \(k\)。

如果我们已经确定了所选元素,如何最小化代价。

$ \sum a$ 不会随顺序变化。

对于 \(b\),可以当做遍历数轴上的 \(k\) 个点所走的路程。

可以直观的看到,对 \(b\) 排序后最优。

因此,所有数先按 \(b\) 排序。

令 \(f[i][j]\) 表示选 \(i\) 个元素,最后一个元素是 \(j\) 的最小代价。

\[f[i][j] = f[i - 1][k] + a[j] + (b[j] - b[k]) \ \ \ \ \ \ \ \ k < j
\]

直接转移是 \(O(n^3)\) 的,考虑前缀 \(min\) 优化。

\[g[i][j] = min(f[i][k] - b[k]) \ \ \ \ \ \ \ \ 1 \le k \le j
\]

所以

\[f[i][j] = g[i - 1][j - 1] + a[j] + b[j]
\]
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的更多相关文章

  1. Codeforces Round #258 (Div. 2)[ABCD]

    Codeforces Round #258 (Div. 2)[ABCD] ACM 题目地址:Codeforces Round #258 (Div. 2) A - Game With Sticks 题意 ...

  2. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  3. Codeforces Round #268 (Div. 2) ABCD

    CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...

  4. Codeforces Round #449 (Div. 2)ABCD

    又掉分了0 0. A. Scarborough Fair time limit per test 2 seconds memory limit per test 256 megabytes input ...

  5. Codeforces Round #143 (Div. 2) (ABCD 思维场)

    题目连链接:http://codeforces.com/contest/231 A. Team time limit per test:2 seconds memory limit per test: ...

  6. Codeforces Round #248 (Div. 2) (ABCD解决问题的方法)

    比赛链接:http://codeforces.com/contest/433 A. Kitahara Haruki's Gift time limit per test:1 second memory ...

  7. Codeforces Round #427 (Div. 2)——ABCD

    http://codeforces.com/contest/835 A.拼英语水平和手速的签到题 #include <bits/stdc++.h> using namespace std; ...

  8. Codeforces Round #412 (Div. 2)ABCD

    tourist的剧毒contest,题干长到让人不想做... A.看不太懂题意直接看下面input output note n组里有两数不一样的一组就rated 否则单调不增为maybe,否则unra ...

  9. Codeforces Round #315 (Div. 2) (ABCD题解)

    比赛链接:http://codeforces.com/contest/569 A. Music time limit per test:2 seconds memory limit per test: ...

  10. Codeforces Round #352 (Div. 2) ABCD

    Problems     # Name     A Summer Camp standard input/output 1 s, 256 MB    x3197 B Different is Good ...

随机推荐

  1. [HTML、CSS]细节、经验

    [版权声明]未经博主同意,谢绝转载!(请尊重原创,博主保留追究权) https://blog.csdn.net/m0_69908381/article/details/130134573 出自[进步* ...

  2. 软件发布版本号命名风格(GUN)

    GUN风格: (1)产品初版时,版本号可以为0.1或0.1.0,也可以为1.0或1.0.0: (2)当产品进行了局部修改或bug修正时,主版本号和子版本号都不变,修正版本号+1: (3)当产品在原有的 ...

  3. 使用POI、JavaCsv工具读取excel文件(*.xls , *.xlsx , *.csv)存入MySQL数据库

    首先进行maven的配置:导入相关依赖 1 <dependency> 2 <groupId>org.apache.poi</groupId> 3 <artif ...

  4. [Unity] 为什么文件名和类名需要相同

    挂载脚本时文件名和类名的关联方式 写过Unity脚本的人应该都知道,挂载脚本的文件名和类名必须相同 今天写新功能的时候偶然发现了这个规则的底层逻辑 并且发现这个规则并非必须的,实际上Unity是根据脚 ...

  5. #博弈论,贪心#AT2376 [AGC014D] Black and White Tree

    题目传送门 分析 考虑到先手放一个白点后手必将在相邻位置放一个黑点, 如果没有合适的位置放黑点先手必胜,也就是问是否存在完美匹配, 直接从叶子节点到根贪心匹配即可 代码 #include <cs ...

  6. #树状数组#洛谷 5677 [GZOI2017]配对统计

    题目 分析 考虑处理出所有右端点的能够匹配的左端点,然后用树状数组离线查询 代码 #include <cstdio> #include <cctype> #include &l ...

  7. 一文弄懂java中的Queue家族

    目录 简介 Queue接口 Queue的分类 BlockingQueue Deque TransferQueue 总结 java中Queue家族简介 简介 java中Collection集合有三大家族 ...

  8. 常用的Numpy通用函数列表

    官网来源:Universal functions (ufunc) - NumPy v1.21 Manual 数学运算(Math operations) 表达式 定义 add(x1, x2, /[, o ...

  9. 使用谷歌浏览器打开PDF文件,怎么关闭缩略图

    我们在使用谷歌浏览器浏览PDF文件时,总是会出现章节预览缩略图和工具栏,我们可以使用 参数来控制浏览器不显示出工具栏 #scrollbars=0&toolbar=0&statusbar ...

  10. Qt 桌面服务 QDesktopServices

    使用浏览器打开网址 #include <QDesktopServices> #include <QUrl> QUrl url(QString("https://cn. ...