UVa 11995 - I Can Guess the Data Structure!
2018-02-02 21:37
483 查看
题意
一个包包, 可能是栈, 队列, 优先队列, 或其他操作1代表存入数据
操作2代表拿出顶端/首端的一个元素
思路
本以为是水题, 居然还WA了两次仔细思考 发现有个特殊情况没考虑到: 如果存入数量小于取出数, 那么一定是impossible !!!
AC代码
操作的时候要先判断容器是否非空吖用完要清空容器吖
#include <iostream> #include <cstdio> #include <stack> #include <queue> using namespace std; stack<int> a; queue<int> b; priority_queue<int> c; int main() { int T, x, y; int fa,fb,fc; int one, two; while( ~scanf("%d",&T) ) { fa = 1, fb = 1, fc = 1; one = 0, two = 0; while(T--){ scanf("%d%d",&x,&y); if( x == 1 ){ one++; a.push(y); b.push(y); c.push(y); } else{ two++; if( !a.empty() ){ if( a.top() != y ) fa = 0; else a.pop(); } if( !b.empty() ){ if( b.front() != y ) fb = 0; else b.pop(); } if( !c.empty() ){ if( c.top() != y ) fc = 0; else c.pop(); } } } if( !fa && !fb && !fc || (two > one) ) puts("impossible"); else if( fa + fb + fc > 1 ) puts("not sure"); else if( fa ) puts("stack"); else if( fb ) puts("queue"); else puts("priority queue"); while( !a.empty() ) a.pop(); while( !b.empty() ) b.pop(); while( !c.empty() ) c.pop(); } return 0; }
相关文章推荐
- 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! STL 模拟
- 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】
- Uva 11995 - I Can Guess the Data Structure!
- UVA 11995(p186)----I Can Guess the Data Structure!
- 11995 - I Can Guess the Data Structure! uva
- 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!