HDU 5929 数据结构模拟
来源:互联网 发布:怎么样做淘宝服装模特 编辑:程序博客网 时间:2024/06/05 03:17
#include<bits/stdc++.h>using namespace std;const int MAX=400105;const int BASE=200010;int T,N,Start,End,Flag,temp;char Str[100];set<int> S; //记录0的位置.set<int>::iterator it;/*先分析一下NAND操作:0 NAND 0 = 10 NAND 1 = 11 NAND 0 = 11 NAND 1 = 0因为只有 1 NAND 1 = 0 ,我们记录当前栈中最后一个0的位置,然后看它后面有几个1.如果有奇数个1,则结果为1,如果有偶数个1,则几个为0.*/int main(){ scanf("%d",&T); for (int cases=1; cases<=T; cases++) { scanf("%d",&N); printf("Case #%d:\n",cases); S.clear(); Start=End=BASE,Flag=0; while (N--) { scanf("%s",Str); switch (Str[2]) { case 'S': //PUSH scanf("%d",&temp); if (temp==0) S.insert(End); if (Flag) End--; else End++; break; case 'P': //POP if (Flag) { if (!S.empty()) { it=S.begin(); if (*it<=End+1) S.erase(it); } End++; } else { if (!S.empty()) { it=S.end(); it--; if (*it>=End-1) S.erase(it); } End--; } break; case 'V': //REVERSE if (Flag) { temp=Start; Start=End+1; End=temp+1; Flag=0; } else { temp=Start; Start=End-1; End=temp-1; Flag=1; } break; case 'E': //QUERY if (Start==End) printf("Invalid.\n"); else if (S.empty()) printf("%d\n",abs((End-Start)%2)); else if (Flag) { it=S.end(); it--; temp=*it; int Ans=Start-temp; if (temp>End+1) Ans++; printf("%d\n",Ans%2); } else { it=S.begin(); temp=*it; int Ans=temp-Start; if (temp<End-1) Ans++; printf("%d\n",Ans%2); } break; } } } return 0;}
0 0
- HDU 5929 数据结构模拟
- HDU 4286 Data Handler( 数据结构,双向队列,模拟)
- 数据结构-模拟
- 数据结构-模拟
- hdu 5929 Basic Data Structure 模拟
- HDU 5929 Basic Data Structure (模拟)
- HDU - 5929 Basic Data Structure(模拟+规律)
- Basic Data Structure HDU 5929(模拟)
- 【HDU】5910 Advanced Traffic System【线段树+并查集】【数据结构模拟最短路】
- 【数据结构】 栈的模拟
- 数据结构-模拟银行业务
- 【模拟+数据结构】操作系统
- 【数据结构】银行业务模拟
- 数据结构--银行模拟
- [数据结构]Joseph problem(模拟)
- 9.30数据结构模拟赛
- 【几何模拟】hdu 3286
- hdu 1020 Encoding(模拟)
- POJ2485 Highways 最小生成树
- codeforces 732D Exams
- HDU 5952 Counting Cliques 图DFS
- 在Docker中运行Hadoop+Spark集群
- 二叉搜索树中删除某一结点函数的另外一种实现
- HDU 5929 数据结构模拟
- Js apply()使用详解
- Linux编程用户和用户组的概念
- UVa Online Judge参考程序集合
- CodeForces 733D Kostya the Sculptor 思维题
- 百度分享插件使用经验
- [深度学习论文笔记][Semantic Segmentation] Fully Convolutional Networks for Semantic Segmentation
- HDU-1045-二分图
- 交换机背板带宽、交换容量、包转发率和线速转发的含义