nyoj+stack的简单使用
2015-10-31 18:19
288 查看
点击打开链接
//终于明白了为什么花括号要那样放了。 #include<iostream> #include<stdio.h> #include<stdlib.h> #include<string.h> #include<cstring> #include<string> #include<algorithm> #include<stack> using namespace std; stack<int> s1,s2,s3; int N=0,P=0,Q=0,a=0,b=0; void solve() { int i=0,temp=0; for(i=0; i<Q; i++){ scanf("%d%d",&a,&b); if(a==1){ if(!s1.empty()){ temp=s1.top(); s1.pop(); if(b==2){ if(s2.empty()) s2.push(temp); else{ if(s2.top()<temp){ printf("illegal\n"); return; } else s2.push(temp); } } else if(b==3){ if(s3.empty()) s3.push(temp); else{ if(s3.top()<temp){ printf("illegal\n"); return; } else s3.push(temp); } } } else{ printf("illegal\n"); return; } } if(a==2){ if(!s2.empty()){ temp=s2.top(); s2.pop(); if(b==1){ if(s1.empty()) s1.push(temp); else{ if(s1.top()<temp){ printf("illegal\n"); return; } else s1.push(temp); } } else if(b==3){ if(s3.empty()) s3.push(temp); else{ if(s3.top()<temp){ printf("illegal\n"); return; } else s3.push(temp); } } } else{ printf("illegal\n"); return; } } if(a==3){ if(!s3.empty()){ temp=s3.top(); s3.pop(); if(b==1){ if(s1.empty()) s1.push(temp); else{ if(s1.top()<temp){ printf("illegal\n"); return; } else s1.push(temp); } } else if(b==2){ if(s2.empty()) s2.push(temp); else{ if(s2.top()<temp){ printf("illegal\n"); return; } else s2.push(temp); } } } else{ printf("illegal\n"); return; } } } printf("legal\n"); } int main() { int i=0; scanf("%d",&N); while(N--){ scanf("%d%d",&P,&Q); for(i=P; i>0; i--) s1.push(i); solve(); while(!s1.empty()) s1.pop(); while(!s2.empty()) s2.pop(); while(!s3.empty()) s3.pop(); } return 0; }
相关文章推荐
- Intellij idea13配置tomcat,并实现一个简单的servlet
- 类的静态成员
- 如何通过实现parcelable接口传递值对象
- WebBrowserControl
- SSH客户端(如PuTTY)ssh远程登录Linux非常慢的解决方法
- HDU1174(空间点到直线的距离,用叉积)
- nyoj+二分函数lower_bound+大数组的注意事项
- gdb调试
- PHP面向对象1.3对象中成员的访问和构造析构函数
- android ubuntu no permissions
- nyoj+multiset的使用+数据要用long long
- HDU2199二分法求根
- SQL处理非常见空串
- Phpcms V9广告位循环数据调用
- jsp 的四个作用域 :page、request、session和application的区别 .
- [AHOI2006]文本编辑器editor BZOIJ 1269
- hdu 1050 Asia 2001, Taejon (South Korea)
- nyoj+排列使用了next_permutation函数
- php 操作mongodb
- 第一章初识R语言