UVA 11995 - I Can Guess the Data Structure!【stl】
2015-11-17 20:49
337 查看
原文网址:
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3146
挺恶心的一道题...需要判断多种状态,本来早写出来了,可是因为容器为空的时候,没特别注意,然后一re....
其实自己也在猜测是不是这个原因..........
需要判断三种容器,那么就直接把三种的状态全部模拟一下,然后各个判断,不过个人为了省些时间,直接判断三个,这样程序可读性下降了,不过还凑合........
然而事实上并没有省多少时间..........
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3146
挺恶心的一道题...需要判断多种状态,本来早写出来了,可是因为容器为空的时候,没特别注意,然后一re....
其实自己也在猜测是不是这个原因..........
需要判断三种容器,那么就直接把三种的状态全部模拟一下,然后各个判断,不过个人为了省些时间,直接判断三个,这样程序可读性下降了,不过还凑合........
然而事实上并没有省多少时间..........
#include<stdio.h> #include<queue> #include<stack> using namespace std; int main() { int n,m; // freopen("shuju.txt","r",stdin); while(~scanf("%d",&n)) { stack<int> s; queue<int> q; priority_queue<int> pq; int cnt=0; int kase[3]={0};// 0 栈,1 队列,2 优先队列 for(int i=0;i<n;++i) { int a,b; scanf("%d%d",&a,&b); if(a==1) { s.push(b); q.push(b); pq.push(b); } else { if(s.empty()||s.top()!=b) { kase[0]=1; } if(q.empty()||q.front()!=b) { kase[1]=1; } if(pq.empty()||pq.top()!=b) { kase[2]=1; } if(!s.empty())//好繁琐的三个判断 { s.pop(); } if(!q.empty()) { q.pop(); } if(!pq.empty()) { pq.pop(); } } } if(kase[0]&&kase[1]&&kase[2]) { printf("impossible\n"); } else if(!kase[0]&&kase[1]&&kase[2]) { printf("stack\n"); } else if(kase[0]&&!kase[1]&&kase[2]) { printf("queue\n"); } else if(kase[0]&&kase[1]&&!kase[2]) { printf("priority queue\n"); } else { printf("not sure\n"); } } return 0; }
相关文章推荐
- 在uistoryboard中实现scrollView的添加内容的操作注意事项
- poj 2593Max Sequence【dp】
- mac os slave Slave went offline during the build issue
- My 1st webUI try
- UISegmentedControl 分段控制 一个小demo
- 《iOS Human Interface Guidelines》——Integrating with iOS
- UI 第六天 UISegmentControl UISlider UIImageView
- Frequently Asked Questions in Spark
- UI note1
- UITableView - beginUpdates和endUpdates
- AMD规范与requireJS
- [TwistedFate]滑块UISlider 跑图UIImageView
- UIControl的两个子类 -- UISegmentedControl UISlider
- UI第六天::UIControl及其⼦类
- 【hihocoder1255 2015北京赛区G】【简单模拟 简化写法超棒哦】 Mysterious Antiques in Sackler Museum 四个矩形选三个 恰好拼成大矩形
- Machine Learning week 3 quiz : Logistic Regression
- ios开发系列-UITableController-索引
- How Did Watson Answer —— Automatic Knowledge Acquisition
- 1099. Build A Binary Search Tree
- Hue安装配置