Codeforces Round #826 (Div. 3) A-E
A
题解
知识点:模拟。
时间复杂度 \(O(n)\)
空间复杂度 \(O(n)\)
代码
#include <bits/stdc++.h>
#define ll long long
using namespace std;
bool solve() {
string a, b;
cin >> a >> b;
if (a.back() != b.back()) {
if (a.back() > b.back()) cout << '<' << '\n';
else if (a.back() == b.back()) cout << '=' << '\n';
else cout << '>' << '\n';
}
else if (a.back() == 'S') {
if (a.size() > b.size()) cout << '<' << '\n';
else if (a.size() == b.size()) cout << '=' << '\n';
else cout << '>' << '\n';
}
else if (a.back() == 'L') {
if (a.size() > b.size()) cout << '>' << '\n';
else if (a.size() == b.size()) cout << '=' << '\n';
else cout << '<' << '\n';
}
else cout << '=' << '\n';
return true;
}
int main() {
std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
while (t--) {
if (!solve()) cout << -1 << '\n';
}
return 0;
}
B
题解
知识点:构造。
除了 \(n = 3\) ,其余取末尾两个倒放在前面,然后从 \(1\) 按顺序即可。
时间复杂度 \(O(n)\)
空间复杂度 \(O(n)\)
代码
#include <bits/stdc++.h>
#define ll long long
using namespace std;
bool solve() {
int n;
cin >> n;
if (n == 3) return false;
cout << n << ' ' << n - 1 << ' ';
for (int i = 1;i <= n - 2;i++) cout << i << ' ';
cout << '\n';
return true;
}
int main() {
std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
while (t--) {
if (!solve()) cout << -1 << '\n';
}
return 0;
}
C
题解
知识点:枚举。
暴力枚举可能的第一段作为基准划分,找到合法划分的中段的最大值,取所有合法的最小值。
时间复杂度 \(O(n^2)\)
空间复杂度 \(O(n)\)
代码
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int a[2007];
bool solve() {
int n;
cin >> n;
for (int i = 1;i <= n;i++) cin >> a[i], a[i] += a[i - 1];
int mi = n;
for (int i = 1;i <= n;i++) {
int tag = a[i] - a[0];
int l = i + 1, r = i + 1, tmx = i;
while (l <= n) {
while (r <= n) {
if (a[r] - a[l - 1] > tag) break;
r++;
}
if (a[r - 1] - a[l - 1] == tag) tmx = max(tmx, r - l);
else break;
l = r;
}
if (l > n) mi = min(mi, tmx);
}
cout << mi << '\n';
return true;
}
int main() {
std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
while (t--) {
if (!solve()) cout << -1 << '\n';
}
return 0;
}
D
题解
知识点:模拟,构造。
模拟这个过程,每次对数组元素分组,组大小从 \(2\) 开始倍增,因为大组交换不会改变组内两边元素相对位置,所以从最小的组开始排序。每组比较先把一组分为两半,因为这两半在上一轮的分组排序一定排序好了,然后把两边第一个元素作为代表元比较大小,每次只交换代表元即可,下一轮比较一定是其中较小的代表元比较。
注意到,无论如何交换,都不能改变原数组两两连续分组后的各个元素的相邻元素 (如 12|34|56|78 ,其中两两元素一定相邻)。因此,如果发现某次交换,一组中两半的代表元差值,不是组大小的一半,那一定无解。
时间复杂度 \(O(m)\)
空间复杂度 \(O(m)\)
代码
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int p[300007];
bool solve() {
int m;
cin >> m;
for (int i = 1;i <= m;i++) cin >> p[i];
int cnt = 0;
for (int i = 1;(1 << i) <= m;i++) {
for (int j = 1;j <= m;j += 1 << i) {
if (abs(p[j] - p[j + (1 << i - 1)]) != (1 << i - 1)) return false;
if (p[j] > p[j + (1 << i - 1)]) swap(p[j], p[j + (1 << i - 1)]), cnt++;
}
}
cout << cnt << '\n';
return true;
}
int main() {
std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
while (t--) {
if (!solve()) cout << -1 << '\n';
}
return 0;
}
E
知识点:线性dp。
朴素dp,设 \(dp[i]\) 为 \([1,i]\) 是否合法。考虑 \(b[i]\) 时,可以把其放下一段左侧或者是右侧,因此有转移方程:
if (i - b[i] - 1 >= 0) dp[i] |= dp[i - b[i] - 1];
if (i + b[i] <= n) dp[i + b[i]] |= dp[i - 1];
时间复杂度 \(O(n)\)
空间复杂度 \(O(n)\)
题解
代码
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int b[200007];
bool dp[200007];
bool solve() {
int n;
cin >> n;
for (int i = 1;i <= n;i++) cin >> b[i], dp[i] = 0;
dp[0] = 1;
for (int i = 1;i <= n;i++) {
if (i - b[i] - 1 >= 0) dp[i] |= dp[i - b[i] - 1];
if (i + b[i] <= n) dp[i + b[i]] |= dp[i - 1];
}
if (dp[n]) cout << "YES" << '\n';
else cout << "NO" << '\n';
return true;
}
int main() {
std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
while (t--) {
if (!solve()) cout << -1 << '\n';
}
return 0;
}
Codeforces Round #826 (Div. 3) A-E的更多相关文章
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
- Codeforces Round #262 (Div. 2) 1004
Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
- Codeforces Round #268 (Div. 2) ABCD
CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...
随机推荐
- ArcGIS QGIS学习一:打开shp、geojson地图变形变扁问题(附最新坐标边界下载全国省市区县乡镇)
目录 打开的地图变扁了 修改投影坐标系 等角圆锥投影 Web墨卡托投影 一些要注意的地方 打开的地图变扁了 记得初学GIS软件时,用ArcGIS或QGIS打开省级地图的时候(shp或geojson等格 ...
- 【Go实战基础】创建并完成第一个可执行的 go 程序
实战需求:创建并完成第一个可执行的 go 程序.项目目录:go-001具体实战步骤如下: 一.进入工程目录 cd go-001/ 二. 创建 g001.go 文件 /* * @Author: 菜鸟实战 ...
- ASP.NET Core自定义中间件的方式
ASP.NET Core应用本质上,其实就是由若干个中间件构建成的请求处理管道.管道相当于一个故事的框架,而中间件就相当于故事中的某些情节.同一个故事框架采用不同的情节拼凑,最终会体现出不同风格的故事 ...
- HTML初学者小知识
引用js <script src="链接/js代码位置" type="text/javascript"></script> 引用css ...
- KingbaseES XA 分布式事务
在分布式系统中,各个节点(或者事务参与方)之间在物理上相互独立,各节点之间无法确切地知道其它节点中的事务执行情况,所以多节点之间很难保证ACID,尤其是原子性.如果是单节点的事务,由于存在事务机制,可 ...
- KingbaseES 转义字符
在SQL标准中字符串是用单引号括起来的,在KingbaseES中遵守了该标准,如果在字符串中需要使用到单引号,就需要对其进行转义. 方式一:使用E和反斜杠进行转义 方式二:直接用一个单引号来转义 在K ...
- Kubernetes DevOps: Jenkins
提到基于 Kubernete 的CI/CD,可以使用的工具有很多,比如 Jenkins.Gitlab CI 以及新兴的 drone 之类的,我们这里会使用大家最为熟悉的 Jenkins 来做 CI/C ...
- Kubernetes 调度 - 污点和容忍度详解
当我们使用节点亲和力(Pod 的一个属性)时,它会将Pod吸引到一组节点(作为偏好或硬性要求).污点的行为完全相反,它们允许一个节点排斥一组 Pod. 在 Kubernetes 中,您可以标记(污染) ...
- Logstash & 索引生命周期管理(ILM)
Grok语法 Grok是通过模式匹配的方式来识别日志中的数据,可以把Grok插件简单理解为升级版本的正则表达式.它拥有更多的模式,默认,Logstash拥有120个模式.如果这些模式不满足我们解析日志 ...
- Alertmanager篇
报一直是整个监控系统中的重要组成部分,Prometheus监控系统中,采集与警报是分离的.警报规则在 Prometheus 定义,警报规则触发以后,才会将信息转发到给独立的组件 Alertmanage ...