第一例很简单,把两个差为偶数的列不断合并即可

这种不需要撤销的合并相连数直接用栈来做

/*
如果相邻两列高度差为偶数
那么可以直接消去
*/
#include<bits/stdc++.h>
#include<stack>
using namespace std;
#define maxn 200005
stack<int>stk;
int n,a[maxn];
int main(){
cin>>n;
for(int i=;i<=n;i++)cin>>a[i];
for(int i=;i<=n;i++){
if(stk.empty()){
stk.push(a[i]);
}
else {
if(abs(stk.top()-a[i])%==){
stk.pop();
}
else stk.push(a[i]);
}
}
if(stk.size()<)puts("YES");
else puts("NO");
}

第二例:只能横填

那么只要从最低的开始往上填,即不断将偶数个低列和其周围的列合并

用单调栈完美解决!

#include<bits/stdc++.h>
#include<stack>
using namespace std;
#define maxn 400005
int n,a[maxn],top;
struct Node{
int h,w;
}stk[maxn];
int main(){
cin>>n;
for(int i=;i<=n;i++)cin>>a[i];
for(int i=;i<=n;i++){
if(top==){
stk[++top].h=a[i];
stk[top].w=;
}
else{
if(stk[top].h==a[i])
stk[top].w++;
else if(stk[top].h<a[i]){
while(top && stk[top].h<a[i]){
if(stk[top].w%==){
stk[top-].w+=stk[top].w;
top--;
}
else {
puts("NO");
return ;
}
}
if(stk[top].h==a[i])
stk[top].w++;
else {
stk[++top].h=a[i];
stk[top].w=;
}
}
else if(stk[top].h>a[i]){
stk[++top].h=a[i];
stk[top].w=;
}
}
}
if(top!=){
for(int i=;i<=top;i++)
if(stk[i].w%){
puts("NO");
return ;
} }
puts("YES");
}

思维题+栈的应用——cf1092D有意思的更多相关文章

  1. ZOJ 3829 贪心 思维题

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3829 现场做这道题的时候,感觉是思维题.自己智商不够.不敢搞,想着队友智商 ...

  2. 洛谷 P4749 - [CERC2017]Kitchen Knobs(差分转换+dp,思维题)

    题面传送门 一道挺有意思的思维题. 首先有一个 obvious 的结论,就是对于每个炉子,要么转到哪里都符合条件,要么存在唯一的最大值.对于转到哪儿都符合条件的炉子我们 duck 不必考虑它,故我们只 ...

  3. zoj 3778 Talented Chef(思维题)

    题目 题意:一个人可以在一分钟同时进行m道菜的一个步骤,共有n道菜,每道菜各有xi个步骤,求做完的最短时间. 思路:一道很水的思维题, 根本不需要去 考虑模拟过程 以及先做那道菜(比赛的时候就是这么考 ...

  4. cf A. Inna and Pink Pony(思维题)

    题目:http://codeforces.com/contest/374/problem/A 题意:求到达边界的最小步数.. 刚开始以为是 bfs,不过数据10^6太大了,肯定不是... 一个思维题, ...

  5. 洛谷P4643 [国家集训队]阿狸和桃子的游戏(思维题+贪心)

    思维题,好题 把每条边的边权平分到这条边的两个顶点上,之后就是个sb贪心了 正确性证明: 如果一条边的两个顶点被一个人选了,一整条边的贡献就凑齐了 如果分别被两个人选了,一作差就抵消了,相当于谁都没有 ...

  6. C. Nice Garland Codeforces Round #535 (Div. 3) 思维题

    C. Nice Garland time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  7. PJ考试可能会用到的数学思维题选讲-自学教程-自学笔记

    PJ考试可能会用到的数学思维题选讲 by Pleiades_Antares 是学弟学妹的讲义--然后一部分题目是我弄的一部分来源于洛谷用户@ 普及组的一些数学思维题,所以可能有点菜咯别怪我 OI中的数 ...

  8. UVA 1394 And Then There Was One / Gym 101415A And Then There Was One / UVAlive 3882 And Then There Was One / POJ 3517 And Then There Was One / Aizu 1275 And Then There Was One (动态规划,思维题)

    UVA 1394 And Then There Was One / Gym 101415A And Then There Was One / UVAlive 3882 And Then There W ...

  9. HDU 1029 Ignatius and the Princess IV / HYSBZ(BZOJ) 2456 mode(思维题,~~排序?~~)

    HDU 1029 Ignatius and the Princess IV (思维题,排序?) Description "OK, you are not too bad, em... But ...

随机推荐

  1. ASP.NET 中 ContentType 类型

    在ASP.NET中使用Response.ContentType="类型名";来确定输出格式 不同的ContentType 会影响客户端所看到的效果.默认的ContentType为 ...

  2. linux 下格式化命令小记

    mkfs.ext4 /dev/sda1    # 格式化为ext4分区mkfs.ext3 /dev/sda1    # 格式化为ext3分区mkfs.ext2 /dev/sda1    # 格式化为e ...

  3. c++内存相关函数

    memset void *memset(void *s, int ch, size_t n); 函数解释:将s中当前位置后面的n个字节 (typedef unsigned int size_t )用 ...

  4. windows下安装jenkins初级(1)

    这里是基于Windows系统下安装Jenkins 首先下载jenkins 下载地址:https://jenkins.io/download/ 选择所需要的系统 我这里选择Windows 开始安装 一直 ...

  5. layui中load具体用法

    遮盖窗体,demo: layer.load(,{ // content: "加载中...", shade: [0.4,'#000'], //0.1透明度的白色背景 time:* } ...

  6. lombok @Builder实现原理

    public class Person { private Person(Builder builder) { name = builder.name; age = builder.age; } pr ...

  7. The past is just a story we tell ourselves.

    The past is just a story we tell ourselves.过去是我们说给自己听的故事.

  8. 【优化】碎片OPTIMIZE

    来看看手册中关于 OPTIMIZE 的描述: OPTIMIZE [LOCAL | NO_WRITE_TO_BINLOG] TABLE tbl_name [, tbl_name] ... 如果您已经删除 ...

  9. hibernate(一对多关系)

    代码   public class Main { public static void main(String[] args) { SessionFactory sty = HibernateUtil ...

  10. PDO::beginTransaction

    语法 bool PDO::beginTransaction ( void ) 关闭自动提交模式.自动提交模式被关闭的同时,通过 PDO 对象实例对数据库做出的更改直到调用 PDO::commit() ...