比赛链接

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;
}

最新文章

  1. .net 分布式架构之业务消息队列
  2. spider RPC管理接口
  3. UITableView点击每个Cell,Cell的子内容的收放
  4. Memcache 内存分配策略和性能(使用)状态检查
  5. jQuery.Deferred 源码分析
  6. Android逆向工程初步(一) 15.4.24
  7. oracle,sqlserver,mysql 命令行 开启、关闭所需要的服务
  8. readonly/disable input 问题
  9. Creating Icon Overlay Handlers / 创建图标标记 Handlers (翻译自MSDN) / VC++, Windows, DLL, ATL, COM
  10. MySQL Online DDL 工具之pt-online-schema-change
  11. C# VS2010中,用微软自带的System.Data.OracleClient来连接Oracle数据库
  12. python中的MySQL使用 + pickle使用
  13. vs编码对编译的影响(UTF-8 no BOM编译通不过)
  14. Codeforces 931F - Teodor is not a liar!
  15. Win(Phone)10开发第(2)弹,导出APPX包并签名部署
  16. wikioi 1021 玛丽卡
  17. 关于iis6.0远程溢出漏洞
  18. 【转】word排版宏的使用
  19. 用sc命令查询系统状态
  20. 使用 get post 注意事项

热门文章

  1. Luogu4427 [BJOI2018]求和 (树上差分)
  2. 744. 寻找比目标字母大的最小字母--LeetCode
  3. 项目导入 Vue Router 4 依赖包流程
  4. C++ 一键关闭屏幕
  5. 从HashMap的执行流程开始 揭开HashMap底层实现
  6. Mybatis 懒加载使用及源码分析
  7. 如何使用CSS伪类选择器
  8. grub2配置文件丢失如何修复
  9. FFT/NTT 学习笔记
  10. 可靠的自托管「GitHub 热点速览 v.22.37」