AtCoder Beginner Contest 380 (A~E)题解
A - 123233
遍历字符串统计出现次数即可。
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e6 + 10;
int n, m, k;
int a[N];
signed main() {
string s;
cin >> s;
map<char, int> mp;
for (auto t : s) {
mp[t]++;
}
if (mp['2'] == 2 && mp['1'] == 1 && mp['3'] == 3) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
B - Hurdle Parsing
直接计数,遇到 $ | $ 输出即可。
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e6 + 10;
int n, m, k;
int a[N];
signed main() {
string s;
cin >> s;
int cnt = 0, f = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '|') {
if (f == 1)
cout << cnt << ' ';
cnt = 0;
f = 1;
}
if (s[i] != '|') {
cnt++;
}
}
}
C - Move Segment
题意是将第 $ k $ 个连续的字符 $ 1 $ 段与第 $ k-1 $个段合并。
用 $ vector $ 存储一下连续的每一段然后根据题目要求顺序即可。
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e6 + 10;
int n, m, k;
int a[N];
signed main() {
string s;
cin >> n >> k;
cin >> s;
string now1 = "", now2 = "";
vector<string> a;
for (int i = 0; i < n; i++) {
if (s[i] == '1') {
now1 += s[i];
if (now2.size() != 0) {
// cout << now2 << '\n';
a.push_back(now2);
now2 = "";
}
}
if (s[i] == '0') {
now2 += s[i];
if (now1.size() != 0) {
a.push_back(now1);
// cout << now1 << '\n';
now1 = "";
}
}
}
if (now1.size())
a.push_back(now1);
if (now2.size())
a.push_back(now2);
// for (auto t : a) {
// cout << t << ' ';
// }
cout << '\n';
int cnt = 0, d1 = 0, d2 = 0;
for (int i = 0; i < a.size(); i++) {
if (a[i][0] == '1') {
cnt++;
if (cnt == k - 1) {
d1 = i;
}
if (cnt == k) {
d2 = i;
for (int j = 0; j <= d1; j++) {
cout << a[j];
}
cout << a[d2];
for (int j = d1 + 1; j < a.size(); j++) {
if (j != d2) {
cout << a[j];
}
}
return 0;
}
}
}
}
D - Strange Mirroring
利用对称的思想,观察每次查询的第 $ k $ 个字符最初是由哪个字符演变过来的,并记录演变次数,根据次数判断字符大小写。可以观察发现,每次我们都可以通过对称使得字符串长度减少 $ n*2^x $ 的长度,该长度通过二分查找,多次缩短我们便能找到最初的字符。
时间复杂度:$ O(q*log k) $。
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e6 + 10;
int n, m, k;
int a[N];
int b[100];
signed main() {
string s;
cin >> s;
n = s.size();
s = ' ' + s;
int q;
cin >> q;
vector<int> a;
int x = n;
for (int i = 1; i <= 64; i++) {
if (x > 1e18) break;
a.push_back(x);
x *= 2;
}
for (int i = 0; i < a.size(); i++) {
b[i + 1] = a[i];
}
while (q--) {
cin >> k;
int d = 0;
int cnt = 0;
for (int i = 1; i <= 100; i++) {
int x = lower_bound(b + 1, b + 1 + (int)a.size(), k) - b;
x -= 1;
k -= b[x];
// cout << x << '\n';
if (b[x] != 0)
cnt++;
if (k <= n) break;
}
// cout << k << '\n';
// cout << cnt << '\n';
char x = s[k];
if (cnt % 2 == 0) {
cout << x << ' ';
} else {
if (x >= 'a' && x <= 'z')
cout << (char)(x - 32) << ' ';
else
cout << (char)(x + 32) << ' ';
}
// cout << '\n';
}
}
E - 1D Bucket Tool
使用两个 $ set $ 维护 $ l $ 和 $ r $ 区间,用 $ set<pair<int,int>> $ 维护存在的颜色的区间,使用 $ map<pair<int,int>> $ 维护颜色区间的颜色。每次修改通过二分查找出 $ x $ 分类讨论所在区间段再根据左右区间段颜色 $ c $ ,判断是否需要合并区间,每次修改完成后更新 $ sum $ 数组的值,不断维护 $ stl $ 容器的值,注意不要出现越界的问题,思路不乱维护好就可以了。
真是一次酣畅淋漓的 $ set $ 练习
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e6 + 10;
int n, m, k;
int sum[N];
set<pair<int, int>> col;
set<int> sel, ser;
map<pair<int, int>, int> mp;
void work(pair<int, int> l, pair<int, int> b, pair<int, int> r, int x) {
sel.erase(l.first), sel.erase(b.first), sel.erase(r.first);
ser.erase(l.second), ser.erase(b.second), ser.erase(r.second);
int a = mp[ {l.first, l.second}], bt = x, c = mp[ {r.first, r.second}];
int be = mp[ {b.first, b.second}];
sum[be] -= b.second - b.first + 1;
sum[x] += b.second - b.first + 1;
if (a == bt && bt == c) {
pair<int, int> f = {l.first, r.second};
mp.erase(b), mp.erase(l), mp.erase(r);
mp[f] = x;
col.erase(l), col.erase(r), col.erase(b);
col.insert(f);
sel.insert(l.first), ser.insert(r.second);
} else if (a == bt) {
pair<int, int> f = {l.first, b.second};
mp.erase(b), mp.erase(l);
col.erase(b), col.erase(l);
mp[f] = x;
col.insert(f);
sel.insert(l.first), ser.insert(b.second);
sel.insert(r.first), ser.insert(r.second);
} else if (bt == c) {
pair<int, int> f = {b.first, r.second};
mp.erase(b), mp.erase(r);
col.erase(b), col.erase(r);
mp[f] = x;
col.insert(f);
sel.insert(b.first), ser.insert(r.second);
sel.insert(l.first), ser.insert(l.second);
} else {
pair<int, int> f = {b.first, b.second};
mp[f] = x;
sel.insert(r.first), ser.insert(r.second);
sel.insert(l.first), ser.insert(l.second);
sel.insert(b.first), ser.insert(b.second);
}
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
sel.insert(i), ser.insert(i);
col.insert({i, i});
mp[ {i, i}] = i;
sum[i] += 1;
}
while (m--) {
int op, x, c;
cin >> op;
if (op == 1) {
cin >> x >> c;
auto it1 = sel.lower_bound(x);
auto it2 = ser.lower_bound(x);
if (it1 == sel.end()) {
it1 = --sel.end();
}
if (*it1 > x) it1--;
auto it3 = col.lower_bound({*it1, *it2});
pair<int, int> b = *it3, l, r;
pair<int, int> ed = *--col.end(), be = *col.begin();
if (b != ed) {
it3++;
auto t = col.lower_bound(*it3);
it3--;
r = *t;
}
if (b != be) {
it3--;
auto t = col.lower_bound(*it3);
it3++;
l = *t;
}
work(l, b, r, c);
} else {
cin >> c;
cout << sum[c] << '\n';
}
}
}
AtCoder Beginner Contest 380 (A~E)题解的更多相关文章
- AtCoder Beginner Contest 238 A - F 题解
AtCoder Beginner Contest 238 \(A - F\) 题解 A - Exponential or Quadratic 题意 判断 \(2^n > n^2\)是否成立? S ...
- AtCoder Beginner Contest 221 A~E题解
目录 A - Seismic magnitude scales B - typo C - Select Mul D - Online games E - LEQ 发挥比较好的一场,就来搓篇题解. F ...
- AtCoder Beginner Contest 215 F题题解
F - Dist Max 2 什么时候我才能突破\(F\)题的大关... 算了,不说了,看题. 简化题意:给定\(n\)个点的坐标,定义没两个点的距离为\(min(|x_i-x_j|,|y_i-y_j ...
- AtCoder Beginner Contest 213 F题 题解
F - Common Prefixes 该题也是囤了好久的题目了,看题目公共前缀,再扫一眼题目,嗯求每个后缀与其他后缀的公共前缀的和,那不就是后缀数组吗?对于这类问题后缀数组可是相当在行的. 我们用后 ...
- 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 ...
- KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200) 题解
KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200) 题解 哦淦我已经菜到被ABC吊打了. A - Century 首先把当前年 ...
- AtCoder Beginner Contest 184 题解
AtCoder Beginner Contest 184 题解 目录 AtCoder Beginner Contest 184 题解 A - Determinant B - Quizzes C - S ...
- AtCoder Beginner Contest 173 题解
AtCoder Beginner Contest 173 题解 目录 AtCoder Beginner Contest 173 题解 A - Payment B - Judge Status Summ ...
随机推荐
- java_基本类型
1. 所有的基本类型都是小写 例如 int 2. 所有的类 类型首字母大写 例如String
- Transformer模型:Position Embedding实现
在自然语言处理(NLP)中,Transformer 模型是一个非常重要的里程碑,它通过自注意力(self-attention)机制极大地提高了处理序列数据的能力.在 Transformer 模型中,词 ...
- pipx 使用
pipx 用于在孤立环境中安装和运行 Python 应用程序.类似 Node.js 中的 npx. 安装 macOS: brew install pipx pipx ensurepath Ubuntu ...
- 根据Uri,Cursor没有获取到对应的属性
Android: 背景:调用摄像头,拍摄视频,指定保存的地址,但是返回的Cursor文件,只有名称和大小的属性,没有其他诸如时长,连ID属性都没有 使用 cursor.getInt(cursor.ge ...
- SQL 高级语法 MERGE INTO
根据与源表相联接的结果,对目标表进行插入.更新.删除等操作. 例如,对目标表,如果源表存在的数据则更新,没有的则插入,就可以使用MEREG进行同步. 基本语法 MERGE INTO target_ta ...
- OSG开发笔记(三十):OSG加载动力学仿真K模型文件以及测试Demo
前言 Osg需要打开模型文件,但是遇到显示动力学仿真的K模型文件,.k文件是一种描述材料属性的文件,比如密度.弹性模量等,该模型文件不是常规中间开放格式,无法直接支持,需要自定义解析并且重建三维模 ...
- Spring —— bean生命周期
bean生命周期 生命周期:从创建到消亡的完整过程 bean生命周期:bean从创建到销毁的整体过程 bean生命周期控制:在bean创建后到销毁前做一些事情 方式一:配置控制生命周期 <b ...
- 系统编程-进程-当文件操作遇上fork
我的关联博文: 系统编程-进程-fork深度理解.vfork简介 系统编程-进程-先后fork或open一个文件的区别 test1: lseek基本使用 #include <stdio.h& ...
- Springboot 项目配置 HTTPS
生成证书 输入命令 keytool -genkeypair -alias "boot" -keyalg "RSA" -keystore "boot.k ...
- iOS中使用UITextView设置不同文本部分点击事件小结
最近在项目开发中遇到了设置多行文本,点击蓝色邮箱部分跳转到发邮件页面功能.当然比较简单的方式是多标签单独设置,那样稍显麻烦.我们能不能用一个控件,给某一部分添加点击事件,结果是可以的,UITextVi ...