标签:style blog io os sp for on 数据 div
数据保证a,b不会相同。
2 1
样例输出
legalillegal
来源
[张云聪]原创
上传者
张云聪
题目大意:上边说的很明白了。
思路:就是用三个栈进行模拟过程并判断就可以。
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<stack>
using namespace std;
stack<int> a[4];
int main()
{
int N,P,Q,flag;
cin >> N;
while(N--)
{
flag = 1;
cin >> P >> Q;
for(int i = P; i >= 1; i--)
a[1].push(i);
while(Q--)
{
int x,y;
cin >> x >> y;
if(a[x].empty())
{
flag = 0;
continue;
}
else if(a[y].empty())
{
a[y].push(a[x].top());
a[x].pop();
}
else if(a[x].top() > a[y].top())
{
flag = 0;
continue;
}
else
{
a[y].push(a[x].top());
a[x].pop();
}
}
if(flag)
cout << "legal" << endl;
else
cout << "illegal" << endl;
while(!a[1].empty())
a[1].pop();
while(!a[2].empty())
a[2].pop();
while(!a[3].empty())
a[3].pop();
}
return 0;
}
标签:style blog io os sp for on 数据 div
原文地址:http://blog.csdn.net/lianai911/article/details/41909969