UVA - 11995 I Can Guess the Data Structure! 猜猜数据结构(STL模拟)
来源:互联网 发布:网络格斗游戏排行 编辑:程序博客网 时间:2024/05/16 06:10
大体题意:
有两种操作 1 x 把 x 放到集合里。
2 x 在x中取出的第一个元素是x
问这个集合是优先队列还是普通队列 还是栈。还是不能确定 还是不可能!
思路:
直接拿着三个东西模拟一下即可!
比较简单 具体不多说了,详细见代码:
#include<cstdio>#include<cstring>#include<algorithm>#include<queue>#include<stack>using namespace std;priority_queue<int,vector<int>,less<int> >q;stack<int>s;queue<int>q2;int main(){ int n; while(scanf("%d",&n) == 1){ while(!q.empty())q.pop(); while(!q2.empty())q2.pop(); while(!s.empty())s.pop(); int x,y,z; x = y = z = 1; for (int i = 0; i < n; ++i){ int u,v; scanf("%d %d",&u,&v); if (u == 1){ q.push(v); q2.push(v); s.push(v); continue; } if (x){ if (q.empty() || q.top() != v)x = 0; else q.pop(); } if (y){ if (q2.empty() || q2.front() != v)y = 0; else q2.pop(); } if (z){ if (s.empty() || s.top() != v)z = 0; else s.pop(); } } if (x + y + z > 1)printf("not sure\n"); else if (x + y + z == 0)printf("impossible\n"); else if (x)printf("priority queue\n"); else if (y)printf("queue\n"); else printf("stack\n"); } return 0;}
0 0
- UVA - 11995 I Can Guess the Data Structure! 猜猜数据结构(STL模拟)
- UVA: 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! (数据结构) STL的应用
- UVa 11995 I Can Guess the Data Structure! (STL)
- UVA 11995 I Can Guess the Data Structure!(STL应用)
- UVA - 11995 I Can Guess the Data Structure! STL模板
- UVA 11995 - I Can Guess the Data Structure!【stl】
- UVA 11995I 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 数据结构
- UVA11995 I Can Guess the Data Structure!(数据结构,模拟)
- UVA 11995 I Can Guess the Data Structure!<STL数据结构使用>
- UVA - 11995 I Can Guess the Data Structure!(水题)
- 水题(I Can Guess the Data Structure!,UVA 11995)
- UVA 11995:I Can Guess the Data Structure!(水)
- NYOJ_349 Sorting It All Out 拓扑排序
- UVA 122 Trees on the level 二叉树
- JUnit4:多组数据的单元测试
- 俄罗斯方块----Ubuntu终端游戏
- POJ 3253 Fence Repair(贪心 + 优先队列)
- UVA - 11995 I Can Guess the Data Structure! 猜猜数据结构(STL模拟)
- 【Unity Shader编程】之十五 屏幕高斯模糊(Gaussian Blur)后期特效的实现
- 自定义ViewGroup容器,实现自动换行的流式布局的效果
- PyUnicodeUCS2*问题解决
- 剑指offer面试题7:用两个栈实现队列
- bash_history 和 mysql_history
- 调试中关于__FILE__, __LINE__ 及 __FUNCTION__ 用法
- 关于android studio安装使用问题
- 50道编程小题目之【完数】