比赛链接:Here

AB水题,

C - One More aab aba baa

题意:

  • 给出字符串 \(s\) 和整数 \(k\) ,请输出字典序第 \(k\) 大的原字符串 \(s\) 的排序

思路:

  • 先说简单写法:

    利用 C++ 内置函数 next_permutation 直接排序即可(代码一)

  • 复杂写法:

    枚举情况,设字符串长度为 \(n\) ,那么也就会有 \(2^n\) 种组合(先不管存在一样的),所以可以DFS来进行枚举爆搜(代码二)

int main() {
cin.tie(nullptr)->sync_with_stdio(false);
string s; int k;
cin >> s >> k;
sort(s.begin(), s.end());
while (k > 1) {
next_permutation(s.begin(), s.end());
k -= 1;
}
cout << s;
}
vector<string>vs;
string s, t;
int k, n;
void dfs(int x) {
if (x == 0) {
vs.push_back(t);
return ;
}
for (int i = 0; i < n; ++i) {
if (x & (1 << i)) { // 枚举第 i 位的情况
t.push_back(s[i]);
dfs(x ^ (1 << i));
t.pop_back();
}
}
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
cin >> s >> k;
n = int(s.size());
dfs((1 << n) - 1);
sort(vs.begin(), vs.end());
unique(vs.begin(), vs.end());
cout << vs[k - 1];
}

D - Coprime 2

赛时很可惜这个没做出来QAQ

题意:

  • 给定 \(n\) 个数字,请问在 \(1\sim M\) 中有多少个数字与给出的 \(n\) 个数字互质

思路:

  • 首先像埃拉托色尼筛法一样先把 \([1,M]\)​ 的每个素数筛选出来,
  • 然后把 \(a_i\) 的因子也统计出来(把其中的素数标记)
  • 然后针对被标记的素因子从中删去即可

时间复杂度:\(\mathcal{O}(N\sqrt{\max{A}})\)

const int N = 1e5 + 10;
vector<int> pfact(int x) {
vector<int>ans;
for (int i = 2; i * i <= x; ++i) {
while (x % i == 0) {
x /= i;
ans.push_back(i);
}
}
if (x != 1) ans.push_back(x);
return ans;
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n, m; cin >> n >> m;
vector<bool>st(N, true);
for (int i = 0, x; i < n; ++i) {
cin >> x;
vector<int> v = pfact(x);
for (auto &nx : v) {
if (st[nx]) for (int j = nx; j < N; j += nx) st[j] = false;
}
}
vector<int> ans;
for (int i = 1; i <= m; ++i) if (st[i]) ans.push_back(i);
cout << ans.size() << "\n";
for (int x : ans) cout << x << "\n";
}

E - Chain Contestant

题意:

我们有 \(10\) 种比赛类型:\(AAC, ..., AJC\)​ ,现在有 \(n\) 场比赛每场比赛以 \(AxC\)​ 表示,

RioTian 想要在 \(n\)​ 场比赛中选择并参加至少一项,并且满足以下条件

  • 参加的比赛顺序中,同类型的比赛是连续的

    形式上,参加的 \(x\) 场比赛并且其中的第 \(i\) 个比赛是 \(T_i\) 类型时,对于整数每个三元组 \((i,j,k)\) 使得 \(1\le i < j < k\le x,T_i = T_j\ if\ T_i =T_k\)

求出 \(RioTian\) 参加比赛的方式数 ,取模于 \(998244353\) 。


\[QAQ
\]

考虑状压DP,

设 \(f[i][u][v]\)​ 表示为对于前 \(i\)​ 场比赛,迄今为止参加的比赛集以及最后参加比赛的种类为 \(v\)​ 时的方案数。

\(x\) 为第 \(i\) 场比赛的种类

  • 对于每组 \(U\) 和每一种比赛 \(j\),在 \(f[i][u][j] += f[i - 1][u][j]\) (对应RioTian没有参加第 \(i\) 场比赛时),如果 $ j =x$ 也要加上 \(f[i - 1][u][j]\)​ (对应 RioTian 参加第 \(i\) 场比赛时与上一场参加的比赛类型相同)
  • 对于每个不包含 \(x\)​ 的集合 \(V\)​ 和每种竞赛 \(j\)​ ,将 \(f[i-1][v][j]\)​ 添加到 \(f[i][v^‘][j]\)​​ ,其中 \(v^‘\) 是添加了 \(x\) 的 \(v\) ,对应RioTian参加第 \(i\)​ 次比赛时和他上次参加的比赛不同
  • \(f[i][w][x] += 1\) ,其中 \(W\) 代表仅包含 \(x\) 的集合(对应参加的第一场比赛是第 \(i\) 场比赛的情况)

最后输出 \(\sum f[n][u][j]\)​​ (U为比赛集合,j 为比赛种类)

时间复杂度:\(\mathcal{O}(2^KNK)\)

const int mod = 998244353;
ll f[1024][1024][10];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n; string s;
cin >> n >> s;
for (int i = 1; i <= n; ++i) {
int x = s[i - 1] - 'A';
for (int u = 0; u < 1024; ++u)
for (int j = 0; j < 10; ++j) {
f[i][u][j] = f[i - 1][u][j];
if (j == x) {
f[i][u][j] += f[i - 1][u][j];
f[i][u][j] %= mod;
}
}
for (int v = 0; v < 1024; v++) {
if (v & (1 << x)) continue;
for (int j = 0; j < 10; j++) {
f[i][v | (1 << x)][x] += f[i - 1][v][j];
f[i][v | (1 << x)][x] %= mod;
}
}
f[i][(1 << x)][x]++;
f[i][(1 << x)][x] %= mod;
}
ll ans = 0;
for (int u = 0; u < 1024; ++u) for (int j = 0; j < 10; ++j)
(ans += f[n][u][j]) %= mod;
cout << ans;
}

F - Dist Max 2

F是一道思维题,

先贴一下代码

#include <bits/stdc++.h>
using namespace std; int main() {
int n; cin >> n;
vector<pair<int, int>> v(n);
for (int i = 0; i < n; i++) cin >> v[i].first >> v[i].second;
sort(v.begin(), v.end());
int ok = 0, ng = 1000000001;
while (ng - ok > 1) {
int md = (ok + ng) / 2;
queue<pair<int, int>> que;
bool able = false;
int mi = 1000000001, ma = 0;
for (auto p : v) {
while (!que.empty()) {
if (que.front().first > p.first - md)break;
mi = min(mi, que.front().second); ma = max(ma, que.front().second);
que.pop();
}
if (mi <= p.second - md || ma >= p.second + md) able = true;
que.push(p);
}
if (able) ok = md;
else ng = md;
}
cout << ok << endl;
}

AtCoder Beginner Contest 215 (个人题解 A~F)的更多相关文章

  1. KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200) 题解

    KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200) 题解 哦淦我已经菜到被ABC吊打了. A - Century 首先把当前年 ...

  2. AtCoder Beginner Contest 215 F题题解

    F - Dist Max 2 什么时候我才能突破\(F\)题的大关... 算了,不说了,看题. 简化题意:给定\(n\)个点的坐标,定义没两个点的距离为\(min(|x_i-x_j|,|y_i-y_j ...

  3. 2018.09.08 AtCoder Beginner Contest 109简要题解

    比赛传送门 水题大赛? 全是水题啊!!! T1 ABC333 就是判断是不是两个数都是奇数就行了. 代码: #include<bits/stdc++.h> using namespace ...

  4. AtCoder Beginner Contest 089完整题解

    A - Grouping 2 Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement There a ...

  5. Atcoder Beginner Contest 138 简要题解

    D - Ki 题意:给一棵有根树,节点1为根,有$Q$次操作,每次操作将一个节点及其子树的所有节点的权值加上一个值,问最后每个节点的权值. 思路:dfs序再差分一下就行了. #include < ...

  6. AtCoder Beginner Contest 238 A - F 题解

    AtCoder Beginner Contest 238 \(A - F\) 题解 A - Exponential or Quadratic 题意 判断 \(2^n > n^2\)是否成立? S ...

  7. AtCoder Beginner Contest 137 F

    AtCoder Beginner Contest 137 F 数论鬼题(虽然不算特别数论) 希望你在浏览这篇题解前已经知道了费马小定理 利用用费马小定理构造函数\(g(x)=(x-i)^{P-1}\) ...

  8. AtCoder Beginner Contest 154 题解

    人生第一场 AtCoder,纪念一下 话说年后的 AtCoder 比赛怎么这么少啊(大雾 AtCoder Beginner Contest 154 题解 A - Remaining Balls We ...

  9. AtCoder Beginner Contest 153 题解

    目录 AtCoder Beginner Contest 153 题解 A - Serval vs Monster 题意 做法 程序 B - Common Raccoon vs Monster 题意 做 ...

  10. AtCoder Beginner Contest 177 题解

    AtCoder Beginner Contest 177 题解 目录 AtCoder Beginner Contest 177 题解 A - Don't be late B - Substring C ...

随机推荐

  1. 用友NCC产品API使用指南

    轻易云用友NCC产品API集成专题 open api简介 Open API即开放API,也称开放平台. 所谓的开放API(OpenAPI)是服务型网站常见的一种应用,网站的服务商将自己的网站服务封装成 ...

  2. 【Android】如何去掉默认标题栏

    1.在AndroidManifest.xml文件中修改并添加以下代码 android:theme="@style/Theme.AppCompat.NoActionBar" 2.在你 ...

  3. 23C新特性:True Cache的介绍

    我们的文章会在微信公众号"Oracle恢复实录"和博客网站"https://www.cnblogs.com/www-htz-pw/" 同步更新 ,欢迎关注收藏, ...

  4. [ABC327G] Many Good Tuple Problems

    题目链接 简化题意:有一个 \(n\) 个点的图,问有多少个长度为 \(M\) 的边序列,满足连边后图是二分图. \(n\le 30,m\le 10^9\) 考虑先强制要求无重边. 定义 \(f_{i ...

  5. 理解Mysql索引原理及特性

    作为开发人员,碰到了执行时间较长的sql时,基本上大家都会说"加个索引吧".但是索引是什么东西,索引有哪些特性,下面和大家简单讨论一下. 1 索引如何工作,是如何加快查询速度 索引 ...

  6. 聊聊流式数据湖Paimon(二)

    当前的问题 Apache Paimon 最典型的场景是解决了 CDC (Change Data Capture) 数据的入湖:CDC 数据来自数据库.一般来说,分析需求是不会直接查询数据库的. 容易对 ...

  7. 算法2:Hanoi塔

    汉诺(Hanoi)塔 一.背景介绍 在印度,有这么一个古老的传说:在世界中心贝拿勒斯(在印度北部)的圣庙里,一块黄铜板上插着三根宝石针.印度教的主神梵天在创造世界的时候,在其中一根针上从下到上地穿好了 ...

  8. MOSS对话式大型语言模型

    MOSS是复旦大学自然语言处理实验室发布的一种类似于ChatGPT的会话语言模型.MOSS能够按照用户的指示执行各种自然语言任务,包括回答问题.生成文本.摘要文本.生成代码等.MOSS还能够挑战错误的 ...

  9. MyBatis 的缓存处理

    作为常见的 ORM 框架,在使用 MyBatis 的过程中可以针对相关的查询进行缓存处理以提高查询的性能.本文将简要介绍一下 MyBatis 中默认的一级缓存和二级缓存,以及自定义缓存的处理 MyBa ...

  10. 2023-09-07:用go语言编写。塔子哥最近在处理一些字符串相关的任务 他喜欢 R 字符,因为在某些任务中,这个字符通常表示“正确”的结果 另一方面,他不喜欢 B 字符,因为在某些任务中,这个字符

    2023-09-07:用go语言编写.塔子哥最近在处理一些字符串相关的任务 他喜欢 R 字符,因为在某些任务中,这个字符通常表示"正确"的结果 另一方面,他不喜欢 B 字符,因为在 ...