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

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

/*
如果相邻两列高度差为偶数
那么可以直接消去
*/
#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. vue组件基础之父子传值

    可以看出数据从后端获取过来,最外层的父组件接收数据,子组件不能直接获取,必须由父组件传递,此时使用props,并且父组件的值更新后,子组件的值也会随之更新,但是反过来通过修改子组件props来影响父组 ...

  2. python-面向对象-01课堂笔记

    面向对象 ''''1.面向过程编程   核心是"过程"二字,过程指的是解决问题的步骤,即先干什么再干什么   基于该思想编写程序就好比在编写一条流水线,是一种机械式的思维方式​   ...

  3. C# - *.dll vs *.lib (动态链接库 vs 静态链接库)

    静态库 库(Library)就是一段编译好的二进制代码,加上头文件就可以使用. 静态链接库(Windows 下的*.lib, Linux & Mac 下的 .a).之所以叫做静态,是因为静态库 ...

  4. php Excel导出id

    <form action="{:U('Index/files')}" method="post" enctype="multipart/form ...

  5. Delphi中任务栏状态区的编程

    在Windows桌面的任务栏上有一个凹陷的区域,其中显示着系统时钟以及一些图标,这个长方形的区域便是Windows的任务栏状态区(taskbar status area).本文将介绍使用Borland ...

  6. NOIp2018集训test-9-8(pm) (联考一day2)

    把T1题读错了,想了一个多小时发现不可做.然后打了t2,常数不优秀.然后去打t3,lct,结果打挂爆0了. 然后今天就爆炸了. 如果这是noip我今年就可以直接回去学常规了.学常规多好,多开心. 今天 ...

  7. C++ 将汉字转换成拼音全拼【转载】

    转载自https://www.cnblogs.com/mzhrd/p/4758105.html #include <string> using std::string; //======= ...

  8. linux centos 安装配置varnish

    安装2.0+版本 前期准备: 下载pcre http://sourceforge.net/projects/pcre/files/pcre/ http://optimate.dl.sourceforg ...

  9. LeetCode 1041. Robot Bounded In Circle (困于环中的机器人)

    题目标签:Math 题目让我们判断机器人是否是一直在走一个圈. 当我们把 instructions 走完一遍时候: 1. 如果机器人回到了原点,那么它是在走一个圈. 2. 如果机器人的方向没有改变,那 ...

  10. Spring源码由浅入深系列四 创建BeanFactory

    继上一章refresh之后,上图描述了obtainFreshBeanFactory过程.