版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sugarbliss/article/details/85127862
题目链接:http://codeforces.com/contest/1092/problem/D1
题意:是有n个列,然后输入n个数ai表示每个列当前的砖的个数,然后有任意块2*1和1*2的砖,问最后能不能铺满n*max(ai)
思路:如果相邻的两堆差值为2的倍数则可以成对消去,用栈模拟这个过程,最后判断如果剩余堆的数量大于一,输出NO,反之输出YES。
#include<bits/stdc++.h>
using namespace std;
#define read(x) scanf("%d",&x)
int main()
{
int n, h; read(n);
stack<int> stk; read(h);
stk.push(h);
for(int i = 2; i <= n; i++)
{
read(h);
if(stk.size() && (h - stk.top()) % 2 == 0)
stk.pop();
else stk.push(h);
}
if(stk.size() <= 1) printf("YES\n");
else printf("NO\n");
}