[UVA-11995]I Can Guess the Data Structure!

题意

判断数据结构类型

解析

直接模拟就行

Copy
#include <bits/stdc++.h> using namespace std; const int maxn = 1e4 + 10; bool isstack, isque, ispri; struct Stack { int top, st[maxn]; void clear() { memset(st, 0, sizeof(st)); top = 0; } int pop() { if (top == 0) return -1; return st[top--]; } void insert(int x) { st[++top] = x; } }s; priority_queue<int> q; struct Queue { int que[maxn], tail, head; void clear() { tail = head = 0; memset(que, 0, sizeof(que)); } void insert(int x) { que[++tail] = x; } int pop() { if (tail == head) return -1; return que[++head]; } }qa; inline void Insert(int x) { s.insert(x), qa.insert(x), q.push(x); } inline void check(int x) { if (q.size() == 0 || q.top() != x) ispri = false; if (q.size()) q.pop(); if (qa.pop() != x) isque = false; if (s.pop() != x) isstack = false; } inline void Output() { int cnt = (int)isstack + (int)ispri + (int)isque; if (cnt >= 2) { puts("not sure"); } else if (cnt == 0) { puts("impossible"); } else { if (isstack) { puts("stack"); } else if (ispri) { puts("priority queue"); } else { puts("queue"); } } } int main() { int n; while (~scanf("%d", &n)) { s.clear(); qa.clear(); while (q.size() > 0) q.pop(); isstack = ispri = isque = true; for (int i = 1, opt, x; i <= n; ++ i) { scanf("%d %d", &opt, &x); if (opt & 1) { Insert(x); } else check(x); } Output(); } }
posted @   AlessandroChen  阅读(176)  评论(0编辑  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
点击右上角即可分享
微信分享提示