Codeforces Round #527 (Div. 3)D2(栈,思维)
#include<bits/stdc++.h>
using namespace std;
int a[200007];
stack<int>s;
int main(){
int n;
int mn=0;
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
if(a[i]>mn)
mn=a[i];
}
s.push(a[1]);
int x=0;
for(int i=2;i<=n;i++){
if(!s.empty()){
x=s.top();
if(a[i]==x)
s.pop();
else{
if(a[i]>x){
printf("NO");
return 0;
}
s.push(a[i]);
}
}
else
s.push(a[i]);
}
int y=s.size();
if(y<=1){
if(y==1&&s.top()!=mn)//如果栈内剩下的是最大的元素,它无需与其它元素一同++,非最大是无法和其他一起++的,缺少该判断惨遭hack
printf("NO");
else
printf("YES");
}
else
printf("NO");
return 0;
}
//类似括号匹配
Codeforces Round #527 (Div. 3)D2(栈,思维)的更多相关文章
- Codeforces Round #527 (Div. 3) D2. Great Vova Wall (Version 2) 【思维】
传送门:http://codeforces.com/contest/1092/problem/D2 D2. Great Vova Wall (Version 2) time limit per tes ...
- Codeforces Round #527 (Div. 3) ABCDEF题解
Codeforces Round #527 (Div. 3) 题解 题目总链接:https://codeforces.com/contest/1092 A. Uniform String 题意: 输入 ...
- Codeforces Round #350 (Div. 2) D2. Magic Powder - 2
题目链接: http://codeforces.com/contest/670/problem/D2 题解: 二分答案. #include<iostream> #include<cs ...
- Codeforces Round #546 (Div. 2) D 贪心 + 思维
https://codeforces.com/contest/1136/problem/D 贪心 + 思维 题意 你面前有一个队列,加上你有n个人(n<=3e5),有m(m<=个交换法则, ...
- Codeforces Round #541 (Div. 2) G dp + 思维 + 单调栈 or 链表 (连锁反应)
https://codeforces.com/contest/1131/problem/G 题意 给你一排m个的骨牌(m<=1e7),每块之间相距1,每块高h[i],推倒代价c[i],假如\(a ...
- Codeforces Round #527 (Div. 3) D1. Great Vova Wall (Version 1) 【思维】
传送门:http://codeforces.com/contest/1092/problem/D1 D1. Great Vova Wall (Version 1) time limit per tes ...
- Codeforces Round #527 (Div. 3) 总结 A B C D1 D2 F
传送门 A 贪心的取 每个字母n/k次 令r=n%k 让前r个字母各取一次 #include <bits/stdc++.h> using namespace std; typedef lo ...
- Codeforces Round #594 (Div. 1) D2. The World Is Just a Programming Task (Hard Version) 括号序列 思维
D2. The World Is Just a Programming Task (Hard Version) This is a harder version of the problem. In ...
- Codeforces Round #579 (Div. 3) D2. Remove the Substring (hard version) (思维,贪心)
题意:给你一个模式串\(t\),现在要在主串\(s\)中删除多个子串,使得得到的\(s\)的子序列依然包含\(t\),问能删除的最长子串长度. 题解:首先,我们不难想到,我们可以选择\(s\)头部到最 ...
随机推荐
- php:如何使用PHP排序, key为字母+数字的数组(多维数组)
你还在为如何使用PHP排序字母+数字的数组而烦恼吗? 今天有个小伙伴在群里问:如何将一个key为字母+数字的数组按升序排序呢? 举个例子: $test = [ 'n1' => 22423, 'n ...
- HTML5 学习记录——2
20150826 1.声明文档类型 <!DOCTYPE> 声明HTML是用什么版本写的. 常用声明; 2.HYML头部元素 <head> <title> 定义 ...
- nodejs buffer 总结
JavaScript 语言自身只有字符串数据类型,没有二进制数据类型.Buffer 类,该类用来创建一个专门存放二进制数据的缓存区. 一个 Buffer 类似于一个整数数组,但它对应于 V8 堆内存之 ...
- IpIImage -> CvMat 转换方法
Ipl转为CvMat 一般为这两种方法: 1: /*cvGetMat*/ CvMat matheader; CvMat * mat = cvGetMat(img, &matheader); 2 ...
- Debian for ARM
/************************************************************************* * Debian for ARM * 说明: * ...
- 【转】 Pro Android学习笔记(四八):ActionBar(1):Home图标区
目录(?)[-] Home Icon 源代码 TextView的滚动 返回主activity或指定activity ActionBar在Android 3.0 SDK中为平板引入,在4.0中也 ...
- JSR-303规范,Bean Validation
一: JSR 303是JAVA EE 6中的一项子规范,叫做Bean Validation,官方参考实现是Hibernate Validator,此实现与Hibernate ORM没有任何关系.JSR ...
- 2440移植内核到uboot上,打印乱码
转载请注明出处:http://blog.csdn.net/qq_26093511/article/details/51851368 可能原因: 1. 修改内核 里的晶振大小 arch\arm\mach ...
- C/C++的区别
C和C++的关系:就像是win98跟winXP的关系.C++是在C的基础上增加了新的理论,玩出了新的花样.所以叫C加加. C和C++的区别: C是一个结构化语言,它的重点在于算法和数据结构.C程序的设 ...
- 可定制的分词库——Yaha(哑哈)分词
可定制的分词库——Yaha(哑哈)分词在线测试地址:http://yaha.v-find.com/ 部署于GAE yahademo.appspot.comYaha分词主要特点是把分词过程分成了4个阶段 ...