AtCoder Beginner Contest 215 (个人题解 A~F)
比赛链接: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\) 。
\]
考虑状压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)的更多相关文章
- KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200) 题解
KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200) 题解 哦淦我已经菜到被ABC吊打了. A - Century 首先把当前年 ...
- AtCoder Beginner Contest 215 F题题解
F - Dist Max 2 什么时候我才能突破\(F\)题的大关... 算了,不说了,看题. 简化题意:给定\(n\)个点的坐标,定义没两个点的距离为\(min(|x_i-x_j|,|y_i-y_j ...
- 2018.09.08 AtCoder Beginner Contest 109简要题解
比赛传送门 水题大赛? 全是水题啊!!! T1 ABC333 就是判断是不是两个数都是奇数就行了. 代码: #include<bits/stdc++.h> using namespace ...
- AtCoder Beginner Contest 089完整题解
A - Grouping 2 Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement There a ...
- Atcoder Beginner Contest 138 简要题解
D - Ki 题意:给一棵有根树,节点1为根,有$Q$次操作,每次操作将一个节点及其子树的所有节点的权值加上一个值,问最后每个节点的权值. 思路:dfs序再差分一下就行了. #include < ...
- AtCoder Beginner Contest 238 A - F 题解
AtCoder Beginner Contest 238 \(A - F\) 题解 A - Exponential or Quadratic 题意 判断 \(2^n > n^2\)是否成立? S ...
- AtCoder Beginner Contest 137 F
AtCoder Beginner Contest 137 F 数论鬼题(虽然不算特别数论) 希望你在浏览这篇题解前已经知道了费马小定理 利用用费马小定理构造函数\(g(x)=(x-i)^{P-1}\) ...
- AtCoder Beginner Contest 154 题解
人生第一场 AtCoder,纪念一下 话说年后的 AtCoder 比赛怎么这么少啊(大雾 AtCoder Beginner Contest 154 题解 A - Remaining Balls We ...
- AtCoder Beginner Contest 153 题解
目录 AtCoder Beginner Contest 153 题解 A - Serval vs Monster 题意 做法 程序 B - Common Raccoon vs Monster 题意 做 ...
- AtCoder Beginner Contest 177 题解
AtCoder Beginner Contest 177 题解 目录 AtCoder Beginner Contest 177 题解 A - Don't be late B - Substring C ...
随机推荐
- 随机森林(Random Forest)--- 转载
1 什么是随机森林? 作为新兴起的.高度灵活的一种机器学习算法,随机森林(Random Forest,简称RF)拥有广泛的应用前景,从市场营销到医疗保健保险,既可以用来做市场营销模拟的建模,统计客户来 ...
- 每日总结9.20-phoenix的连接
今天连了phoenix 出现了好多问题,欸 一点点解决,看那个电脑我头都要晕了,jar包和xml文件的问题,总之是解决了 怎么办,我还不会springboot,好多人都学了,我害怕.大家怎么都这么努力 ...
- DDD学习与感悟——总是觉得自己在CRUD怎么办?
一.DDD是什么? DDD全名叫做Domins drives Design:领域驱动设计.再说的通俗一点就是:通过领域建模的方式来实现软件设计. 问题来了:什么是软件设计?为什么要进行软件设计? 软件 ...
- [USACO2007NOVG] Sunscreen
题目描述 To avoid unsightly burns while tanning, each of the$ C (1 ≤ C ≤ 2500) $cows must cover her hide ...
- C# 获取系统DPI缩放比例以及分辨率大小
一般方法 System.Windows.Forms.Screen类 // 获取当前主屏幕分辨率 int screenWidth = Screen.PrimaryScreen.Bounds.Width; ...
- 【scikit-learn基础】--『监督学习』之 岭回归
岭回归(Ridge Regression)是一种用于处理共线性数据的线性回归改进方法.和上一篇用基于最小二乘法的线性回归相比,它通过放弃最小二乘的无偏性,以损失部分信息.降低精度为代价来获得更实际和可 ...
- NetSuite 开发日记:解决导入 CSV 与 Excel 文件时中文乱码问题
Backgroud 在使用SheetJS库导入带有中文的CSV文件时,中文被解析为了乱码 Analysis 乱码肯定是编码问题 确定CSV的编码,可使用VS Code.记事本来查看 修改CSV文件编码 ...
- Win10遇到服务器启动失败 80端口被占用如何解决
Win10提示"服务器启动失败,80端口被占用"怎么办?具体解决方法如下 步骤如下: 1.以管理员身份运行cmd; 2.输入:net stop http 注:如果提示是否真的需要停 ...
- 由浅入深理解C#中的事件
目录 本文较长,给大家提供了目录,可以直接看自己感兴趣的部分. 前言 有关事件的概念 示例 简单示例 标准 .NET 事件模式 使用泛型版本的标准 .NET 事件模式 补充 总结 参考 ...
- 文心一言 VS 讯飞星火 VS chatgpt (44)-- 算法导论6.1 1题
一.在高度为h的堆中,元素个数最多和最少分别是多少? 文心一言: 在高度为 h 的二叉搜索树(BST)中,元素个数最多和最少的情况分别如下: 1.最多情况:当每个节点都包含两个子节点时,BST 中的元 ...