UVA - 11995 I Can Guess the Data Structure!(水题)
来源:互联网 发布:交换机互联 网络名 编辑:程序博客网 时间:2024/06/05 09:50
解析:
水题,定义三种数据结构然后后模拟其情况,然后判断就可以了。
AC代码
#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <cstdlib>#include <queue>#include <stack>using namespace std;typedef long long ll;const int INF = 0x3f3f3f3f;const int N = 1005;int ele[N],oper[N];int n;int main() { bool ans[3]; while(scanf("%d", &n) != EOF) { memset(ans, true, sizeof(ans)); priority_queue<int> pri_que; queue<int> que; stack<int> st; for(int i = 0; i < n; i++) { scanf("%d%d", &oper[i], &ele[i]); if(oper[i] == 1) { pri_que.push(ele[i]); que.push(ele[i]); st.push(ele[i]); }else { if(st.empty() || ele[i] != st.top()) ans[0] = false; else st.pop(); if(que.empty() || ele[i] != que.front()) ans[1] = false; else que.pop(); if(pri_que.empty() || ele[i] != pri_que.top()) ans[2] = false; else pri_que.pop(); } } int cnt = 0; for(int i = 0; i < 3; i++) { if(ans[i]) cnt++; } if(cnt == 0) puts("impossible"); else if(cnt >= 2) puts("not sure"); else if(ans[0]) puts("stack"); else if(ans[1]) puts("queue"); else if(ans[2]) puts("priority queue"); } return 0;}
0 0
- UVA - 11995 I Can Guess the Data Structure!(水题)
- 水题(I Can Guess the Data Structure!,UVA 11995)
- 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!
- 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!
- HDU - 1394 Minimum Inversion Number(树状数组 or 线段树)
- unity3d 参考坐标系
- merge two sorted lists
- 油画商城
- online_judge_1201
- UVA - 11995 I Can Guess the Data Structure!(水题)
- 用Matlab制作图像块颜色提取工具(二)
- JSP小项目,会员管理系统之实现登录功能
- .net学习第六天
- 进程与线程关系
- 头文件中的 ifndef/define/endif
- WF从入门到精通(第十一章):并行活动
- 大芬油画村《首届全国中青年油画展》
- (六十二)纯代码搭建UI