Codeforces Global Round 9 C. Element Extermination
题目链接:https://codeforces.com/contest/1375/problem/C
题意
给出一个大小为 $n$ 的排列 $a$,如果 $a_i < a_{i+1}$,则可以选择移去二者之一,判断排列最终能否只剩一个数。
题解一
考虑小于 $a_0$ 的所有的数,如果这些数都可以移去,那么剩余的数都大于 $a_0$,显然也都可以移去。
所以可以记录大于 $a_0$ 的每个数的位置,然后标记它们左端可以移除的数,最后判断小于 $a_0$ 的数是否都能移除即可。
代码
#include <bits/stdc++.h>
using namespace std; void solve() {
int n; cin >> n;
int a[n] = {};
int pos[n] = {};
for (int i = 0; i < n; i++) {
cin >> a[i];
--a[i];
pos[a[i]] = i;
}
bool can_remove[n] = {};
bool vis[n] = {};
for (int i = n - 1; i > a[0]; i--) {
for (int j = pos[i] - 1; j >= 0 and !vis[j]; j--) {
can_remove[a[j]] = true;
vis[j] = true;
}
}
bool ok = true;
for (int i = 0; i < a[0]; i++)
if (!can_remove[i]) ok = false;
cout << (ok ? "YES" : "NO") << "\n";
} int main() {
int t; cin >> t;
while (t--) solve();
}
题解二
一个小于 $a_0$ 的数只有在最右端的时不能移除,所以判断 $a_0 < a_{n - 1}$ 即可。
代码
#include <bits/stdc++.h>
using namespace std; void solve() {
int n; cin >> n;
int a[n] = {};
for (int i = 0; i < n; i++)
cin >> a[i];
cout << (a[0] < a[n - 1] ? "YES" : "NO") << "\n";
} int main() {
int t; cin >> t;
while (t--) solve();
}
Codeforces Global Round 9 C. Element Extermination的更多相关文章
- Codeforces Global Round 9 C. Element Extermination (思维,栈)
题意:有一个长度\(n\)的序列,如果\(a_{i}<a_{i+1}\),那么可以选择删除\(a_{i}\)或者\(a_{i+1}\),再继续操作,问是否能够将序列删到只剩一个元素. 题解:感觉 ...
- CodeForces Global Round 1
CodeForces Global Round 1 CF新的比赛呢(虽然没啥区别)!这种报名的人多的比赛涨分是真的快.... 所以就写下题解吧. A. Parity 太简单了,随便模拟一下就完了. B ...
- Codeforces Global Round 1 - D. Jongmah(动态规划)
Problem Codeforces Global Round 1 - D. Jongmah Time Limit: 3000 mSec Problem Description Input Out ...
- Codeforces Global Round 2 题解
Codeforces Global Round 2 题目链接:https://codeforces.com/contest/1119 A. Ilya and a Colorful Walk 题意: 给 ...
- Codeforces Global Round 1 (A-E题解)
Codeforces Global Round 1 题目链接:https://codeforces.com/contest/1110 A. Parity 题意: 给出{ak},b,k,判断a1*b^( ...
- Codeforces Global Round 3
Codeforces Global Round 3 A. Another One Bites The Dust 有若干个a,有若干个b,有若干个ab.你现在要把这些串拼成一个串,使得任意两个相邻的位置 ...
- Codeforces Global Round 1 (CF1110) (未完结,只有 A-F)
Codeforces Global Round 1 (CF1110) 继续补题.因为看见同学打了这场,而且涨分还不错,所以觉得这套题目可能会比较有意思. 因为下午要开学了,所以恐怕暂时不能把这套题目补 ...
- 【手抖康复训练1 】Codeforces Global Round 6
[手抖康复训练1 ]Codeforces Global Round 6 总结:不想复习随意打的一场,比赛开始就是熟悉的N分钟进不去时间,2333,太久没写题的后果就是:A 题手抖过不了样例 B题秒出思 ...
- Codeforces Global Round 11 个人题解(B题)
Codeforces Global Round 11 1427A. Avoiding Zero 题目链接:click here 待补 1427B. Chess Cheater 题目链接:click h ...
随机推荐
- mysql 应用 持续更新
1.安装方法 贴出,my.ini # MySQL Server Instance Configuration File # -------------------------------------- ...
- Docker 镜像基础(三)
基于Dockerfile制作yum版本nginx镜像 [root@node-2 ~]# mkdir /opt/nginx [root@node-2 ~]# cd /opt/nginx/ ## 创建Do ...
- DHCP最佳实践(一)
这是Windows DHCP最佳实践和技巧的最终指南. 如果您有任何最佳做法或技巧,请在下面的评论中发布它们. 在本指南(一)中,我将分享以下DHCP最佳实践和技巧. 不要将DHCP放在您的域控制器上 ...
- innobackupex: Connecting to MySQL server with DSN 'dbi:mysql
[root@ma src]# innobackupex --user=root /root/backup --no-timestamp InnoDB Backup Utility v1.5.1-xtr ...
- P2986 [USACO10MAR]伟大的奶牛聚集(思维,dp)
题目描述 Bessie is planning the annual Great Cow Gathering for cows all across the country and, of cours ...
- Linux Ubuntu系统版本通过Crontab设置定时任务的执行
Linux Ubuntu系统版本通过Crontab设置定时任务的执行 本文由本人收集网络信息总结而来 特别鸣谢:https://linux.zone/2258 1 crontab 简单介绍以及语法使用 ...
- mysql忽略表中的某个字段不查询
业务场景 1.表中字段较多 2.查询不需要表中某个字段的数据 语句如下: SELECT CONCAT(' select ',GROUP_CONCAT(COLUMN_NAME),' from ', TA ...
- python3多进程 进程池 协程并发
一.进程 我们电脑的应用程序,都是进程,进程是资源分配的单位.进程切换需要的资源最大,效率低. 进程之间相互独立 cpu密集的时候适合用多进程 #多 ...
- Fixing SQL Injection: ORM is not enough
Fixing SQL Injection: ORM is not enough | Snyk https://snyk.io/blog/sql-injection-orm-vulnerabilitie ...
- 有状态(Stateful)应用的容器化 - 云+社区 - 腾讯云 https://cloud.tencent.com/developer/article/1020178
有状态(Stateful)应用的容器化 - 云+社区 - 腾讯云 https://cloud.tencent.com/developer/article/1020178