比赛链接

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. java-RandomAccessFile操作以及IO流简单使用

    1.1RandomAccessFile--使用RAF读写基本类型数据,以及了解Raf的指针操作 write有相对应的写入基本类型的方法 void seek(Long pos)调整RAF指针位置,可以在 ...

  2. ArkUI 自定义组件

    基础入门 组件可以把一段代码封装起来,目的是提高这一段代码的复用率,并且也可以减少开发人员多次编写相同的代码.一旦组件定义好了之后,在页面中只需要通过<element /> 标签引入进来就 ...

  3. 对Jmeter-基础线程组的一点解释

    概述 线程组是一个测试计划的起点.测试计划中所有元件的运行都必须依托于线程组.每个线程组都会独立的运行测试计划,互不干扰 线程数 线程数在并发用户场景下表示用户数,比如100用户同时发起请求 线程数在 ...

  4. 上传代码到GitHub仓库

    上传代码到GitHub仓库 准备工作 意思是自从 21 年 8 月 13 后不再支持用户名密码的方式验证了,需要创建个人访问令牌(personal access token). 这里就不多说了 Git ...

  5. .NET 7 性能改进 -- 至今为止最快的.NET平台

    2022年8月31日 Stephen Toub 发布的关于 .NET 7 性能改进的博客, 核心主题是 .NET 7 速度很快. 这篇博客非常的长,我尝试将它拷贝到Word 里,拷贝的时间都花了几分钟 ...

  6. 关于 Math.random()生成指定范围内的随机数的公式推导

    关于 Math.random()生成指定范围内的随机数的公式推导 在 java 中,用于生成随机数的 Math 方法 random()只能生成 0-1 之间的随机数,而对于生成指定区间,例如 a-b ...

  7. django路由匹配、反向解析、无名有名反向解析、路由分发、名称空间

    目录 django请求生命周期流程图 1.Django请求的生命周期的含义 2.Django请求的生命周期图解及流程 3.Django的请求生命周期(分布解析) 路由层 1.路由匹配 2.path转换 ...

  8. Vue3 封装 Element Plus Menu 无限级菜单组件

    本文分别使用 SFC(模板方式)和 tsx 方式对 Element Plus el-menu 组件进行二次封装,实现配置化的菜单,有了配置化的菜单,后续便可以根据路由动态渲染菜单. 1 数据结构定义 ...

  9. Kafka开启SASL认证 【windowe详细版】

    一.JAAS配置 Zookeeper配置JAAS zookeeper环境下新增一个配置文件,如zk_server_jass.conf,内容如下: Server { org.apache.kafka.c ...

  10. 点赞和取消点赞实现Redis缓存(只思路)

    思路:点赞.取消点赞 --> Redis --> (每两个小时)存到数据库(MySQL),所以就相当于每次查询或者存储都需要先经过Redis,而查询的目的是为了判断用户的点赞状态(已点赞o ...