思维题+栈的应用——cf1092D有意思
第一例很简单,把两个差为偶数的列不断合并即可
这种不需要撤销的合并相连数直接用栈来做
/*
如果相邻两列高度差为偶数
那么可以直接消去
*/
#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有意思的更多相关文章
- ZOJ 3829 贪心 思维题
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3829 现场做这道题的时候,感觉是思维题.自己智商不够.不敢搞,想着队友智商 ...
- 洛谷 P4749 - [CERC2017]Kitchen Knobs(差分转换+dp,思维题)
题面传送门 一道挺有意思的思维题. 首先有一个 obvious 的结论,就是对于每个炉子,要么转到哪里都符合条件,要么存在唯一的最大值.对于转到哪儿都符合条件的炉子我们 duck 不必考虑它,故我们只 ...
- zoj 3778 Talented Chef(思维题)
题目 题意:一个人可以在一分钟同时进行m道菜的一个步骤,共有n道菜,每道菜各有xi个步骤,求做完的最短时间. 思路:一道很水的思维题, 根本不需要去 考虑模拟过程 以及先做那道菜(比赛的时候就是这么考 ...
- cf A. Inna and Pink Pony(思维题)
题目:http://codeforces.com/contest/374/problem/A 题意:求到达边界的最小步数.. 刚开始以为是 bfs,不过数据10^6太大了,肯定不是... 一个思维题, ...
- 洛谷P4643 [国家集训队]阿狸和桃子的游戏(思维题+贪心)
思维题,好题 把每条边的边权平分到这条边的两个顶点上,之后就是个sb贪心了 正确性证明: 如果一条边的两个顶点被一个人选了,一整条边的贡献就凑齐了 如果分别被两个人选了,一作差就抵消了,相当于谁都没有 ...
- 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 ...
- PJ考试可能会用到的数学思维题选讲-自学教程-自学笔记
PJ考试可能会用到的数学思维题选讲 by Pleiades_Antares 是学弟学妹的讲义--然后一部分题目是我弄的一部分来源于洛谷用户@ 普及组的一些数学思维题,所以可能有点菜咯别怪我 OI中的数 ...
- 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 ...
- 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 ...
随机推荐
- Hive之explode和lateral view
Hive之explode 一. explode, 行转列. 1.1. 用于array类型的数据 table_name 表名 array_col 为数组类型的字段 new_col array_col被e ...
- Django项目从新建到运行
返回主目录:Django框架 内容目录: 一.安装之前 二.Django安装 三.创建项目 四.配置 一.安装之前 安装django之前你需要注意的几个事项: 1.版本问题 建议使用1.11.11左右 ...
- PWM,SBUS,PPM信号转模拟电压的方案
PWM,SBUS,PPM信号转模拟电压的方案 -----------------本文由"麦粒电子"撰写,并提供相应产品服务.---------------- 案例场景 有个内部采用 ...
- tomcat nio apr
NIO[root@localhost ~]# vim /usr/local/tomcat9/conf/server.xml<Connector port="8080" pro ...
- session复制
环境描述:(三台服务器 系统:7.6)192.168.200.111 nginx192.168.200.112 tomcat192.168.200.113 tomcat环境配置:192.168.200 ...
- PKUSC订正
Day1 T2:最大前缀和 枚举答案集合(不直接枚举答案数,相当于状态的离散化),这个集合成为答案当且仅当存在方案使得答案集合的排列后缀和>=0(如果<0就可以去掉显然更优),答案补集的前 ...
- SQLServer2008上的SDE备份和还原
一.备份 右键数据库>任务>备份.选择完整模式,导出为xxx.bak文件即可. 二.还原 1.创建sde用户名,新建同名数据库xxx,并指定sde为xxx的拥有者. 2.在master上创 ...
- Android SDK Download
{ https://www.androiddevtools.cn/ }
- 暴力模拟——cf988E
很简单的题,就是模拟一下 #include<bits/stdc++.h> using namespace std; #define ll long long ll n,a[],len; i ...
- NX二次开发-UFUN工程图更新视图UF_DRAW_update_one_view
NX9+VS2012 #include <uf.h> #include <uf_draw.h> #include <uf_obj.h> #include <u ...