CSU-ACM2017暑假集训比赛1 A - I Can Guess the Data Structure! -uva111995
2017-07-26 20:17
483 查看
UVA11995
.........本场唯一做出的题,还错了n+次
题目大意:给你一个n个数对,第一个个数为1或2,后面的数x代表一个元素值,现在有一个不知道具体是什么的容器,1代表将元素x存进容器,2代表取出来的元素是x.....问你这个容器是啥。
思路:直接创建这几个容器然后同时进行模拟,完全符合输入的就是了
坑:取出元素前别忘了判空,不然会RE。
极丑的ac代码
#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <algorithm> #include <queue> #include <stack> using namespace std; int flag_q,flag_s,flag_pq; int sum,ans; queue<int>q; stack<int>s; priority_queue<int>pq; int n,x,y; int main() { while(scanf("%d",&n)!=EOF) { ans=sum=flag_q=flag_s=flag_pq=0; for(int i=0;i<n;i++) { scanf("%d%d",&x,&y); if(x==1) { q.push(y); s.push(y); pq.push(y); } else if(x==2) { if(!q.empty()&&q.front()==y) flag_q++; if(!s.empty()&&s.top()==y) flag_s++; if(!pq.empty()&&pq.top()==y) flag_pq++; sum++; if(!q.empty()) q.pop(); if(!s.empty()) s.pop(); if(!pq.empty()) pq.pop(); } } if(flag_s==sum) ans++; if(flag_q==sum) ans++; if(flag_pq==sum) ans++; if(ans==0) printf("impossible\n"); else if(ans>1) printf("not sure\n"); else { if(flag_s==sum) printf("stack\n"); else if(flag_q==sum) printf("queue\n"); else printf("priority queue\n"); } while(!q.empty()) q.pop(); while(!s.empty()) s.pop(); while(!pq.empty()) pq.pop(); } return 0; }
相关文章推荐
- 【暑假】[实用数据结构]UVa11995 I Can Guess the Data Structure!
- 1/20集训一 STL E.(模拟stack queue priority_queue) I Can Guess the Data Structure!
- 【暑假】[实用数据结构]UVa11995 I Can Guess the Data Structure!
- CSU-ACM2017暑假集训比赛8 - C - GCD Table - CodeForces - 582A
- 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!
- CSU-ACM2017暑假集训比赛7 - E - Courses - HDU - 1083
- UVA - 11995 I Can Guess the Data Structure!
- I Can Guess the Data Structure! uva11995
- UVA 11995 I Can Guess the Data Structure! (STL的应用)
- UVA 11995 I Can Guess the Data Structure!
- CSU-ACM2017暑假集训比赛2 CodeForces - 724D
- UVA 11995 I Can Guess the Data Structure!
- (UVA 11995) I Can Guess The Data Structure! --抽象数据结构判断
- UVA11995 I Can Guess the Data Structure!(数据结构,模拟)
- UVA - 11995 I Can Guess the Data Structure! 猜猜数据结构(STL模拟)
- UVA 11995 I Can Guess the Data Structure!
- CSU-ACM2017暑假集训比赛2 C - (╯°口°)╯(┴—┴