题意:

给一排砖,每列的高度$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. UGUI源码之Selectable

    Selectable是Button.InputField.Toggle.ScrollBar.Slider.Dropdown的基类. Selectable的继承的类与接口如下: public class ...

  2. DHCP服务器搭建

    一.服务端安装配置 1.安装dhcp相关软件包 执行命令:yum install dhcp dhcp-devel -y #通过yum安装dhcp软件包 2.编辑配置dhcp的配置文件,文件路径:/et ...

  3. Android学习进度二

    在最新的Android开发中,Google已经使用了新的开发技术,即使用Jectpack来开发App.所以今天我主要学习了这方面的知识. Jetpack 是一套库.工具和指南,可帮助开发者更轻松地编写 ...

  4. web实现点击左侧导航,右侧加载不同的网页(这种布局多用于后台管理系统)

    (1)实现方法:采用ajax实现点击左侧菜单,右侧加载不同网页(在整个页面无刷新的情况下实现右侧局部刷新,用到ajax注意需要在服务器环境下运行,从HBuilder自带的服务器中打开浏览效果即可) ( ...

  5. 【一头扎进Spring】 01 | 从 HelloWorld 开始看Spring

    Spring 是一个开源框架. Spring 为简化企业级应用开发而生. 使用 Spring 可以使简单的 JavaBean 实现以前只有 EJB 才能实现的功能. Spring 是一个 IOC(DI ...

  6. RocketMQ客户端加载流程

     这节介绍RocketMQ客户端的启动流程,即Consumer和Producer的启动流程. 1. 客户端demo  首先先看下客户端的demo Producer: public class Sync ...

  7. Spring学习记录6——ThreadLocal简介

    Spring通过各种模板类降低了开发者使用各种数据持久化技术的难度.这些模板类是线程安全的,所以 多个DAO可以复用同一个模板实例而不会发生冲突.在使用模板类访问底层数据时,模板类需要绑定数据连接或者 ...

  8. cf 450b 矩阵快速幂(数论取模 一大坑点啊)

    Jzzhu has invented a kind of sequences, they meet the following property: You are given x and y, ple ...

  9. C# 二分法的解读

    注:一定是有序的数组,才可以使用这种算法,如果数组没有排序则先进行排序后再调用此方法. 1.二分法是做什么的呢? 当然是查找数组中的数据了,开个玩笑,哈哈哈. 2.为啥要用这种方式呢? 二分顾名思义, ...

  10. ThinkPad全家族机型对比

    如图所示