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 ...
随机推荐
- 聊一聊 C# 中让人惶恐的 Bitmap
一:背景 1. 讲故事 在.NET高级调试的旅程中,我常常会与 Bitmap 短兵相接,它最大的一个危害就是会让程序抛出匪夷所思的 OutOfMemoryException,也常常会让一些.NET开发 ...
- wget 提示 "无法验证 xxxx.xxx 的由 “xxx” 颁发的证书: 无法本地校验颁发者的权限。"
有一天在使用 wget 下载文件时,出现了无法验证证书的提示: $ wget https://github.com/zayronxio/Mkos-Big-Sur/releases/download/0 ...
- Mysql table 调整table的字符集和校对规则
ALTER TABLE `xxxx`.`xxx` CHARACTER SET = utf8mb4 , COLLATE = utf8mb4_0900_ai_ci ;
- due to missing onError handler in the subscribe() method call.
某日,APP端忽然与后台,一建立连接,就报错,然后断开, 之前都好好的,十分确信代码没有问题,可是跑着就是报错,百思不得其解, 终于发现,不知道怎么回事,配置文件里的stomp的地址配的居然不是我印象 ...
- 解决auditwheel repair过程rpath被修改的问题
问题背景 AuditWheel是一个用于修复Python的whl包的工具,例如在这个CyFES开源库中,因为使用到了Cython和CUDA编译动态链接库的技术,方便Python调用.但是在编译CUDA ...
- .net core 负载均衡取客户端真实IP
一个网关代码(.net core 3.1),部署到负载均衡器有故障,发现获取到的客户端IP都是内网IP了,负载均衡用的是阿里云的SLB . 记录一下修改过程 在Strup.cs 中的 Configur ...
- 合合信息AI图像内容安全新技术亮相WAIC2023,防范“生成式造假”
开年以来,多个图像生成软件在全球迅速蹿红,其作画逼真程度"技惊四座".AI一路"狂飙",让生成.篡改等多形式的图片伪造的门槛变得更低,由此引发的隐患也令人忧虑. ...
- CPP在内网穿透技术的思考
概述 内网穿透是一种技术,用于在私有局域网(LAN)中的设备与外部网络(如互联网)之间建立通信通道,使得外部设备可以访问内网中的服务.由于内网设备通常位于防火墙或 NAT(网络地址转换)设备之后,外部 ...
- Identity – Custom Entity
扩展属性 Custom Entity 指的是我们想对 Identity 的几个 Entity 做修改. 比如 User 要多一些 property, 或者 Id 用 int 而不是默认的 GUID. ...
- manim边学边做--图形间集合关系
几何图形间的集合关系,是数学和几何学中的一个基本概念, 通过计算不同形状(如圆形.矩形.三角形等)的交集和并集等关系,可以实现复杂的图形处理和视觉效果. manim中提供了4种计算几何形状间集合关系的 ...