比赛链接

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的更多相关文章

  1. 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 ...

  2. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  3. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  4. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  5. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  6. 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 ...

  7. 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 ...

  8. Codeforces Round #371 (Div. 1)

    A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...

  9. Codeforces Round #268 (Div. 2) ABCD

    CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...

随机推荐

  1. Spring源码 19 IOC getBean

    参考源 https://www.bilibili.com/video/BV1tR4y1F75R?spm_id_from=333.337.search-card.all.click https://ww ...

  2. virtual box 安装虚拟机如何全屏

    最近由于要进行微信小程序的开发.可恶的腾讯狗没有提供linux版的开发工具!不得以安装虚拟机!暗号虚拟机后发现win10的界面实在是太小,于是乎去解决这个问题!其实很简单,一般来是说直接点虚拟机面板上 ...

  3. java单线程100%利用率

    容器内就获取个cpu利用率,怎么就占用单核100%了呢 背景:这个是在centos7 + lxcfs 和jdk11 的环境上复现的 目前这个bug已经合入到了开源社区, 链接为 https://git ...

  4. Mybatis的ResultMap与limit分页查询

    ResultMap主要解决的是:属性名和字段不一致 如果在pojo中设置的是一个名字,在数据库上又是另一个名字,那么查询出来的结果或者其他操作的结果就为null. //在pojo中 private S ...

  5. QT学习(三)

    首先整理一下编码的方法.对于一个待解决的问题,首先应该将大问题分解成小问题,将小问题划分为小小问题... 然后再进行类的抽象,将划分成的问题和类进行对应.然后再对划分的小..问题进行具体的处理分析,划 ...

  6. 跨语言调用C#代码的新方式-DllExport

    简介 上一篇文章使用C#编写一个.NET分析器文章发布以后,很多小伙伴都对最新的NativeAOT函数导出比较感兴趣,今天故写一篇短文来介绍一下如何使用它. 在以前,如果有其他语言需要调用C#编写的库 ...

  7. Kubernetes DevOps: Gitlab

    Gitlab 官方提供了 Helm 的方式在 Kubernetes 集群中来快速安装,但是在使用的过程中发现 Helm 提供的 Chart 包中有很多其他额外的配置,所以我们这里使用自定义的方式来安装 ...

  8. 7. Ceph 高级篇 - RBD块设备回收站、快照、克隆

    文章转载自:https://mp.weixin.qq.com/s?__biz=MzI1MDgwNzQ1MQ==&mid=2247485298&idx=1&sn=b83fda07 ...

  9. 1.nexus的安装

    1,Nexus 介绍 Nexus是什么 Nexus 是一个强大的maven仓库管理器,它极大地简化了本地内部仓库的维护和外部仓库的访问. 不仅如此,他还可以用来创建yum.pypi.npm.docke ...

  10. MySQL学习(2)---MySQL数据类型

    ps:此随笔基于mysql 5.7.*版本. 补充: UNSIGNED:所有整数类型都可以有一个可选(非标准)UNSIGNED属性.无符号类型可用于在列中仅允许非负数存在,或者当开发者需要该列的较大数 ...