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 设置页面导航动态active类样式的添加
在用php制作项目中,一般都是把页头和页脚分离出来.页头导航在选中状态时会有一些样式,例如active等,当页面在首页时候,导航的首页也应该是active的样式,那么,怎么用php控制这些样式的添加和 ...
- spring boot: 在maven中装入springframework框架
1.在maven 的pom.xml中加入 <dependency> <groupId>org.springframework</groupId> <artif ...
- SpringMVC注解示例
1.web.xml <servlet> <servlet-name>dispatcherServlet</servlet-name> <servlet-cla ...
- 关于ios::sync_with_stdio(false);和 cin.tie(0)加速c++输入输出流
原文地址:http://www.hankcs.com/program/cpp/cin-tie-with-sync_with_stdio-acceleration-input-and-output.ht ...
- 利用bootsrap控件 实现文件上传功能
源代码实例:https://github.com/kartik-v/bootstrap-fileinput 一.jsp页面 <%@ page language="java" ...
- 2013VS快捷键
VS2013常用快捷键: 1.回到上一个光标位置/前进到下一个光标位置 1)回到上一个光标位置:使用组合键“Ctrl + -”: 2)前进到下一个光标位置:“Ctrl + Shift + - ”. ...
- Android中高效的显示图片之一 ——加载大图
在网上看了不少文章,发现还是官方文档介绍最详细,把重要的东西简单摘要出来.详细可看官方文档地址 ( http://www.bangchui.org/read.php?tid=9 ) . 在应用中显示图 ...
- POJ1379:Run Away
我对模拟退火的理解:https://www.cnblogs.com/AKMer/p/9580982.html 我对爬山的理解:https://www.cnblogs.com/AKMer/p/95552 ...
- POJ2080:Calendar(计算日期)
Calendar Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 12842 Accepted: 4641 Descrip ...
- python的WeakKeyDictionary类和weakref模块的其他函数
python的WeakKeyDictionary类和weakref模块的其他函数 # -*- coding: utf-8 -*- # @Author : ydf # @Time : 2019/6/13 ...