UVa 11995 I Can Guess the Data Structure!
来源:互联网 发布:淘宝刷心悦会封号吗 编辑:程序博客网 时间:2024/06/03 23:14
#include <iostream>#include <cstdio>#include <cstring>#include <stack>#include <queue>#include <map>using namespace std;const int maxn = 1010;int a[maxn], b[maxn];int n;int check1(){ queue<int>q; for(int i=0;i<n;++i){ if(a[i]==1){ q.push(b[i]); } else { if(q.empty())return 0; int x = q.front(); if(x!=b[i])return 0; q.pop(); } } return 1;}int check2(){ priority_queue<int>que; for(int i=0;i<n;++i){ if(a[i]==1){ que.push(b[i]); } else { if(que.empty())return 0; int x = que.top(); if(x!=b[i]){return 0;} que.pop(); } } return 1;}int check3(){ stack<int>s; for(int i=0;i<n;++i){ if(a[i]==1){ s.push(b[i]); } else { if(s.empty())return 0; int x = s.top(); if(x!=b[i]){return 0;} s.pop(); } } return 1;}int main(){ // freopen("in.txt","r",stdin); // int n; //被这个N坑惨了 while(scanf("%d",&n)==1){ for(int i=0;i<n;++i)scanf("%d%d",&a[i],&b[i]); int f1 = check1(); int f2 = check2(); int f3 = check3(); if(!f1&&!f2&&!f3)printf("impossible\n"); else if(f1&&!f2&&!f3)printf("queue\n"); else if(!f1&&f2&&!f3)printf("priority queue\n"); else if(!f1&&!f2&&f3)printf("stack\n"); else printf("not sure\n"); } return 0;}
0 0
- uva - 11995 - I Can Guess the Data Structure!
- Uva-11995-I Can Guess the Data Structure!
- Uva 11995 - I Can Guess the Data Structure!
- UVA 11995 I Can Guess the Data Structure!
- uva 11995 I Can Guess the Data Structure!
- uva 11995 I Can Guess the Data Structure!(STL)
- UVA 11995 I Can Guess the Data Structure!
- UVA 11995 I Can Guess the Data Structure!
- uva 11995 - I Can Guess the Data Structure!
- Uva 11995 - I Can Guess the Data Structure! (判断数据类型)
- UVa:11995 I Can Guess the Data Structure!
- UVA - 11995 I Can Guess the Data Structure!
- UVa 11995 I Can Guess the Data Structure! (STL)
- UVA 11995 I Can Guess the Data Structure!
- UVA 11995 I Can Guess the Data Structure!(STL应用)
- UVa 11995 I Can Guess the Data Structure!
- uva 11995 I Can Guess the Data Structure!
- 11995 - I Can Guess the Data Structure! uva
- 浅谈土地利用图件缩编方法的应用研究
- UVa 536 Tree Recovery
- UVa 10895 Matrix Transpose
- 使用HAProxy、PHP、Redis和MySQL支撑10亿请求每周架构细节
- UVa 548 Tree
- UVa 11995 I Can Guess the Data Structure!
- Android笔记之——framework框架
- 求两个日期之间间隔的天数,Python实现
- Android笔记之——APK的运行状态
- Android笔记——-Binder类框架
- PAT 1044. Shopping in Mars
- PAT_B_字符串-04. 字符串逆序(15)
- PAT_B_字符串-02. 删除字符串中的子串(20)
- PAT_B_字符串-01. 在字符串中查找指定字符(15)