题意:

给一排砖,每列的高度$a_i$,问是否可以放1*2的砖,使得n列高度一样,砖只能横着放

思路:

每两个相邻的高度相同的砖可以变成大于等于它的高度的任意高度

所以像这样的

123321

是不满足题意的,因为两边的相同的高度没法合在一起

只有像这样的

321123

才满足

所以,满足题意的墙应该像上述一样几个“凹”的高度的组合加上最多一列高度为h的墙

这个h应该满足h<=max(a),准确来说应该是等于

拿栈搞一搞就行了

代码:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<vector>
#include<map>
#include<functional> #define fst first
#define sc second
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lc root<<1
#define rc root<<1|1
#define lowbit(x) ((x)&(-x)) using namespace std; typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PLL; const db eps = 1e-;
const int mod = 1e9+;
const int maxn = 2e5+;
const int maxm = 2e6+;
const int inf = 0x3f3f3f3f;
const db pi = acos(-1.0); stack<int>s; int main(){
int n;
scanf("%d", &n);
int mx = -;
for(int i = ; i <= n; i++){
int x;
scanf("%d", &x);
mx = max(mx, x);
if(!s.empty()){
if(s.top() < x){
return printf("NO"),;
}
if(s.top() == x){
s.pop();
}
else if(s.top() > x){
s.push(x);
}
}
else s.push(x);
}
if(s.size() > ) return printf("NO"),;
else if(s.size() == ){
if(s.top() < mx) return printf("NO"),;
}
printf("YES");
return ;
}
/*
*/

Codeforces 1092 D2 Great Vova Wall (Version 2) (栈)的更多相关文章

  1. 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 ...

  2. CodeForces Round #527 (Div3) D2. Great Vova Wall (Version 2)

    http://codeforces.com/contest/1092/problem/D2 Vova's family is building the Great Vova Wall (named b ...

  3. Codeforces Round #527-D1. Great Vova Wall (Version 1)(思维+栈)

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  4. D2. Great Vova Wall (Version 2)

    l链接 [https://codeforces.com/contest/1092/problem/D2] 题意 和D1一样只是不能竖直放了 分析 水平放的话,就只可能是相邻等时才可以,而且你会发现 只 ...

  5. 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 ...

  6. CodeForces Round #527 (Div3) D1. Great Vova Wall (Version 1)

    http://codeforces.com/contest/1092/problem/D1 Vova's family is building the Great Vova Wall (named b ...

  7. D1. Great Vova Wall (Version 1)

    链接 [https://codeforces.com/contest/1092/problem/D1] 题意 给你n个位置墙的高度,现在你有2×1 砖块,你可以竖直或者水平放置 问你是否可以使得所有位 ...

  8. CF1092(div3):Great Vova Wall (栈)(还不错)

    D1. Great Vova Wall (Version 1): 题意:给定长度为N的墙,以及每个位置的一些高度,现在让你用1*2的砖和2*1的砖去铺,问最后能否铺到高度一样. 思路:分析其奇偶性,在 ...

  9. Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) D2. Optimal Subsequences (Hard Version) 数据结构 贪心

    D2. Optimal Subsequences (Hard Version) This is the harder version of the problem. In this version, ...

随机推荐

  1. RAID阵列

    • 廉价冗余磁盘阵列– Redundant Arrays of Inexpensive Disks– 通过硬件/软件技术,将多个较小/低速的磁盘整合成一个大磁盘– 阵列的价值:提升I/O效率.硬件级别 ...

  2. 动态规划最短路径LintcodeNO110

    动态规划最短路径LintcodeNO110 简单的dp题,没啥好说的... class Solution { public: /** * @param grid: a list of lists of ...

  3. Faceted project metadata file "/.settings/org.eclipse.wst.common.project.facet.core.xml" could not be read

    转载自 https://blog.csdn.net/qing_gee/article/details/79397052 Eclipse启动后项目报了下图这个错误,说是org.eclipse.wst.c ...

  4. mongodb学习(二)——基本的数据操作

    数据操作(重点) 数据库的核心--CRUD,增加和删除较为简单,查询和修改较复杂 查询 关系运算符 $gt 大于 $lt 小于 $gte 大于等于 $lte 小于等于 $eq | (key: valu ...

  5. 求一个数的阶乘在 m 进制下末尾 0 的个数

    题意 : 求一个数 n 的阶层在 m 进制下末尾 0 的个数 思路分析 : 如果是 10 进制地话我们是很容易知道怎么做的,数一下其对 5 约数地个数即可,但是换成 m 进制的话就需要先将 m 分解质 ...

  6. 初识 ST 表

    推荐博客 : https://blog.csdn.net/BerryKanry/article/details/70177006 ST表通常用于RMQ问题中,询问某个区间的最值这类问题中 ST表的核心 ...

  7. TCP/IP协议与HTTP协议(二)

    TCP/IP协议是传输层协议,主要解决数据如何在网络中传输,而HTTP是应用层协议,主要解决如何包装数据. 1.TCP连接 手机能够使用联网功能是因为手机底层实现了TCP/IP协议,可以使手机终端通过 ...

  8. Docker学习(三)认识Docker和常用命令

    Docker学习(三)认识Docker和常用命令 Docker体系结构 docker服务端,作为服务的提供方,核心进程 docker daemon,所有docker命令都是通过这个进程完成的 REST ...

  9. crawler碎碎念6 豆瓣爬取操作之获取数据

    import requests from lxml import etree s = requests.Session() for id in range(0,251,25): url ='https ...

  10. 创建过滤扩展方法 Creating Filtering Extension Methods 精通ASP-NET-MVC-5-弗瑞曼 Listing 4-17