UVA - 11995 I Can Guess the Data Structure!
2015-03-31 20:24
134 查看
题目大意:给你一个移动方式,判断它是队列,栈,还是优先队列。
解题思路:直接用STL里面的队列,栈,和优先队列去模拟,出现矛盾说明不是
解题思路:直接用STL里面的队列,栈,和优先队列去模拟,出现矛盾说明不是
#include <cstdio> #include <queue> #include <stack> using namespace std; int main() { int n; while (scanf("%d", &n) != EOF) { stack<int> st; queue<int> qu; priority_queue<int> pq; int S = 1, Q = 1, P = 1; for (int i = 0; i < n; i++) { int c, x; scanf("%d%d", &c, &x); if (c == 1) { st.push(x); qu.push(x); pq.push(x); } else { if (st.empty()) { S = Q = P = 0; continue; } if (S) S = (st.top() == x); if (Q) Q = (qu.front() == x); if (P) P = (pq.top() == x); st.pop(); qu.pop(); pq.pop(); } } if (S + Q + P > 1) puts("not sure"); else if (S) puts("stack"); else if (Q) puts("queue"); else if (P) puts("priority queue"); else puts("impossible"); } return 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!(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! (STL的应用)
- UVA 11995 I Can Guess the Data Structure!【模拟】
- UVa 11995 I Can Guess the Data Structure! (STL)
- uva11995 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! (数据结构) 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!(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!