题目链接:https://codeforces.com/contest/1092/problem/D1
题意:给你n个ai,ai表示第i堵墙的高度,现在都一个1*2的砖头,问:能否把这片墙砌成高度一直的墙?
题解:一般问你YES or NO 的问题,就不用想太复杂,直接推理一下就好。
这里我们可以这样想,相邻的两块初始墙的高度假如是2的倍数,那么这两块墙一定能砌成相同的高度,故我们可以把这两块墙移掉,因为不会影响后面的结果。
代码:
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<stack>
using namespace std;
stack<int> sta;
int main()
{
int n;
while(~scanf("%d",&n))
{
while(!sta.empty())
sta.pop();
for(int i=1;i<=n;i++)
{
int x;
scanf("%d",&x);
///相邻为2的倍数,移除
if(sta.size()&&(x-sta.top())%2==0)
sta.pop();
else sta.push(x);
}
if(sta.size()<=1) puts("YES");
else puts("NO");
}
return 0;
}