题目链接: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的更多相关文章

  1. Codeforces Global Round 9 C. Element Extermination (思维,栈)

    题意:有一个长度\(n\)的序列,如果\(a_{i}<a_{i+1}\),那么可以选择删除\(a_{i}\)或者\(a_{i+1}\),再继续操作,问是否能够将序列删到只剩一个元素. 题解:感觉 ...

  2. CodeForces Global Round 1

    CodeForces Global Round 1 CF新的比赛呢(虽然没啥区别)!这种报名的人多的比赛涨分是真的快.... 所以就写下题解吧. A. Parity 太简单了,随便模拟一下就完了. B ...

  3. Codeforces Global Round 1 - D. Jongmah(动态规划)

    Problem   Codeforces Global Round 1 - D. Jongmah Time Limit: 3000 mSec Problem Description Input Out ...

  4. Codeforces Global Round 2 题解

    Codeforces Global Round 2 题目链接:https://codeforces.com/contest/1119 A. Ilya and a Colorful Walk 题意: 给 ...

  5. Codeforces Global Round 1 (A-E题解)

    Codeforces Global Round 1 题目链接:https://codeforces.com/contest/1110 A. Parity 题意: 给出{ak},b,k,判断a1*b^( ...

  6. Codeforces Global Round 3

    Codeforces Global Round 3 A. Another One Bites The Dust 有若干个a,有若干个b,有若干个ab.你现在要把这些串拼成一个串,使得任意两个相邻的位置 ...

  7. Codeforces Global Round 1 (CF1110) (未完结,只有 A-F)

    Codeforces Global Round 1 (CF1110) 继续补题.因为看见同学打了这场,而且涨分还不错,所以觉得这套题目可能会比较有意思. 因为下午要开学了,所以恐怕暂时不能把这套题目补 ...

  8. 【手抖康复训练1 】Codeforces Global Round 6

    [手抖康复训练1 ]Codeforces Global Round 6 总结:不想复习随意打的一场,比赛开始就是熟悉的N分钟进不去时间,2333,太久没写题的后果就是:A 题手抖过不了样例 B题秒出思 ...

  9. Codeforces Global Round 11 个人题解(B题)

    Codeforces Global Round 11 1427A. Avoiding Zero 题目链接:click here 待补 1427B. Chess Cheater 题目链接:click h ...

随机推荐

  1. js 必须为字母或下划线, 一旦创建不能修改

    <div class="form-group"> <label class="col-lg-2 control-label" for=&quo ...

  2. P4292 [WC2010]重建计划 点分治+单调队列

    题目描述 题目传送门 分析 看到比值的形式就想到 \(01分数规划\),二分答案 设当前的值为 \(mids\) 如果存在\(\frac{\sum _{e \in S} v(e)}{|S|} \geq ...

  3. Flutter 基础组件:文本、字体样式

    // 文本.字体样式 import 'package:flutter/material.dart'; class TextFontStyle extends StatelessWidget { // ...

  4. 相同的class的各位object互为友元(friend)

    相同的class的各位object互为友元(friend) 这句话是啥意思? 我们来看一段代码: 1 class complex{ 2 3 private: 4 5 int r,i; 6 public ...

  5. python学习笔记 | selenium各浏览器驱动下载地址

    Chrome http://chromedriver.storage.googleapis.com/index.html 不同的Chrome的版本对应的chromedriver.exe 版本也不一样, ...

  6. redis持久化怎么选?成年人从来不做选择...

    前言 面试官:你知道 redis 是的怎么做持久化的吗? 我:我知道 redis 有两种方式,一种是 RDB,一种是 AOF. 面试官:那这两种方式具体是怎么做的,它们的区别是什么,生产环境中到底应该 ...

  7. 【ASM】介绍Oracle自带的一些ASM维护工具 (kfod/kfed/amdu)

    转自:http://blog.csdn.net/wenzhongyan/article/details/47043253 非常感谢作者的文章,很有价值!至此转载,非常感谢 1.前言 ASM(Autom ...

  8. LeetCode700. 二叉搜索树中的搜索

    题目 简单递归 1 class Solution { 2 public: 3 TreeNode* searchBST(TreeNode* root, int val) { 4 if(!root) re ...

  9. os-hackos-3-docker提权

    0x00 cewl http://192.168.43.179/websec/爬取页面所有的单词做成字典 hydra -l contact@hacknos.com -P cewl.txt 192.16 ...

  10. SAP中的事务锁

    我们知道sap中的事物锁tcode是SM01. 细细研究发现,其实无外乎就是将tstc表中的事务码对应的字段CINFO的值加上HEX20 解锁就是还原成原来的值. 当然也发现了,调用了一个系统函数AU ...