思路

简单题,用栈,队列,优先队列直接模拟即可

代码

  1. #include <cstdio>
  2. #include <algorithm>
  3. #include <cstring>
  4. #include <queue>
  5. #include <stack>
  6. using namespace std;
  7. queue<int> q;
  8. stack<int> S;
  9. priority_queue<int> pq;
  10. int n;
  11. int main(){
  12. while(scanf("%d",&n)==1){
  13. while(!q.empty())
  14. q.pop();
  15. while(!S.empty())
  16. S.pop();
  17. while(!pq.empty())
  18. pq.pop();
  19. bool isS=true,isq=true,ispq=true;
  20. for(int i=1;i<=n;i++){
  21. int opt,x;
  22. scanf("%d %d",&opt,&x);
  23. if(opt==1){
  24. q.push(x);
  25. pq.push(x);
  26. S.push(x);
  27. }
  28. else{
  29. if(q.empty())
  30. isq=false;
  31. if(pq.empty())
  32. ispq=false;
  33. if(S.empty())
  34. isS=false;
  35. if(isq){
  36. int t=q.front();
  37. if(t!=x)
  38. isq=false;
  39. q.pop();
  40. }
  41. if(ispq){
  42. int t=pq.top();
  43. if(t!=x)
  44. ispq=false;
  45. pq.pop();
  46. }
  47. if(isS){
  48. int t=S.top();
  49. if(t!=x)
  50. isS=false;
  51. S.pop();
  52. }
  53. }
  54. }
  55. if((!ispq)&&(!isq)&&(!isS))
  56. printf("impossible\n");
  57. else if((ispq)&&(!isq)&&(!isS))
  58. printf("priority queue\n");
  59. else if((!ispq)&&(isq)&&(!isS))
  60. printf("queue\n");
  61. else if((!ispq)&&(!isq)&&(isS))
  62. printf("stack\n");
  63. else
  64. printf("not sure\n");
  65. }
  66. return 0;
  67. }

UVA11995 I Can Guess the Data Structure!的更多相关文章

  1. 【暑假】[实用数据结构]UVa11995 I Can Guess the Data Structure!

    UVa11995  I Can Guess the Data Structure! 思路:边读边模拟,注意empty的判断! 代码如下: #include<iostream> #inclu ...

  2. uva-11995 - I Can Guess the Data Structure!(栈,优先队列,队列,水题)

    11995 - I Can Guess the Data Structure! There is a bag-like data structure, supporting two operation ...

  3. [LeetCode] All O`one Data Structure 全O(1)的数据结构

    Implement a data structure supporting the following operations: Inc(Key) - Inserts a new key with va ...

  4. [LeetCode] Add and Search Word - Data structure design 添加和查找单词-数据结构设计

    Design a data structure that supports the following two operations: void addWord(word) bool search(w ...

  5. [LeetCode] Two Sum III - Data structure design 两数之和之三 - 数据结构设计

    Design and implement a TwoSum class. It should support the following operations:add and find. add - ...

  6. Finger Trees: A Simple General-purpose Data Structure

    http://staff.city.ac.uk/~ross/papers/FingerTree.html Summary We present 2-3 finger trees, a function ...

  7. Mesh Data Structure in OpenCascade

    Mesh Data Structure in OpenCascade eryar@163.com 摘要Abstract:本文对网格数据结构作简要介绍,并结合使用OpenCascade中的数据结构,将网 ...

  8. ✡ leetcode 170. Two Sum III - Data structure design 设计two sum模式 --------- java

    Design and implement a TwoSum class. It should support the following operations: add and find. add - ...

  9. leetcode Add and Search Word - Data structure design

    我要在这里装个逼啦 class WordDictionary(object): def __init__(self): """ initialize your data ...

随机推荐

  1. elk-(七)

    最终架构确定为  logs--->blieb--->redis/kafka--->logstash--->es--->kibana 注意:  geoip下载地址: wge ...

  2. react表单的一些小例子

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. C#winform窗体实现对sql server数据库的增删改查

    1.运行效果截图 2.输入用户名,密码进行查询 查找成功则显示 查找不成功显示用户信息不存在 3.输入用户名与密码,向数据库中添加用户信息 添加后数据库表信息 4.查看全部信息 5.根据编号信息进行查 ...

  4. HTML经典模板总结(地址)

    HTML经典模板总结 地址:http://download.csdn.net/tag/html%E6%A8%A1%E6%9D%BF?from=singlemessage

  5. JSON.parse()和JSON.stringify()的解析与用途

    JSON.parse()和JSON.stringify()的解析与用途 1.parse用于从一个字符串中解析出json对象 如: var str = '{"name":" ...

  6. 关于STM32时钟系统

    初学STM32,感觉最蛋疼的是它的时钟系统,每次看到它的那个时钟树就有点晕,虽然看了很多这方面的资料,甚至也已经写过很多STM32的模块代码,做过一些小项目,但一直还是对这一块模模糊糊,似懂非懂,所以 ...

  7. 43-3-STM32的CAN外设

    1.STM32 的芯片中具有 bxCAN 控制器 (Basic Extended CAN), 它支持 CAN 协议 2.0A 和2.0B 标准. 2.外设中具有 3 个发送邮箱,发送报文的优先级可以使 ...

  8. python练习题-day13

    1.获取移动平均值 def wrapper(fun): def inner(*args,**kwargs): ret=fun(*args,**kwargs) ret.__next__() return ...

  9. pandas处理时间序列(2):DatetimeIndex、索引和选择、含有重复索引的时间序列、日期范围与频率和移位、时间区间和区间算术

    一.时间序列基础 1. 时间戳索引DatetimeIndex 生成20个DatetimeIndex from datetime import datetime dates = pd.date_rang ...

  10. Angela启动步骤

    1.在web目录下执行 grunt watch (如果不在目录下执行不能识别,当然首先安装node.js) 2.随便改一个文件,会自动重新生成代码(在dest目录下会生成可执行的代码) 3.如果有de ...