2016CCPC东北地区大学生程序设计竞赛1008/HDU 5929 模拟
Basic Data Structure
Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 78 Accepted Submission(s): 12
∙
PUSH x: put x on the top of the stack, x must be 0 or 1.
∙
POP: throw the element which is on the top of the stack.
Since it is too simple for Mr. Frog, a famous mathematician who can prove "Five points coexist with a circle" easily, he comes up with some exciting operations:
∙
REVERSE: Just reverse the stack, the bottom element becomes the top element of the stack, and the element just above the bottom element becomes the element just below the top elements... and so on.
∙
QUERY: Print the value which is obtained with such way: Take the element from top to bottom, then do NAND operation one by one from left to right, i.e. If atop,atop−1,⋯,a1
is corresponding to the element of the Stack from top to the bottom, value=atop
nand atop−1
nand ... nand a1
. Note that the Stack will not change after QUERY operation. Specially, if the Stack is empty now,you need to print ”Invalid.”(without quotes).
By the way, NAND is a basic binary operation:
∙
0 nand 0 = 1
∙
0 nand 1 = 1
∙
1 nand 0 = 1
∙
1 nand 1 = 0
Because Mr. Frog needs to do some tiny contributions now, you should help him finish this data structure: print the answer to each QUERY, or tell him that is invalid.
), which indicates the number of test cases.
For each test case, the first line contains only one integers N (2≤N≤200000
), indicating the number of operations.
In the following N lines, the i-th line contains one of these operations below:
∙
PUSH x (x must be 0 or 1)
∙
POP
∙
REVERSE
∙
QUERY
It is guaranteed that the current stack will not be empty while doing POP operation.
In the first sample: during the first query, the stack contains only one element 1, so the answer is 1. then in the second query, the stack contains 0, l (from bottom to top), so the answer to the second is also 1. In the third query, there is no element in the stack, so you should output Invalid.
0
后面 1
的个数的奇偶性就行。感谢评论区 hack数据
1
10
PUSH 0
REVERSE
QUERY
PUSH 1
PUSH 1
REVERSE
POP
QUERY
POP
QUERY
代码中已经标记更改
/******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
#include<bits/stdc++.h>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<bitset>
#include<math.h>
#include<vector>
#include<string>
#include<stdio.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
#define A first
#define B second
const int mod=;
const int MOD1=;
const int MOD2=;
const double EPS=0.00000001;
//typedef long long ll;
typedef __int64 ll;
const ll MOD=;
const int INF=;
const ll MAX=1ll<<;
const double eps=1e-;
const double inf=~0u>>;
const double pi=acos(-1.0);
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
int t;
char str[];
map<int,int> mp;
int l,r;
int l0,r0;
int exm;
int flag=;
int n;
set<int>se;
set<int>::iterator it;
int biao=;
int main()
{
scanf("%d",&t);
{
for(int k=; k<=t; k++)
{
se.clear();
mp.clear();
biao=;
scanf("%d",&n);
l=r=;
printf("Case #%d:\n",k);
for(int i=; i<=n; i++)
{
scanf("%s",str);
if(strcmp(str,"PUSH")==)
{
scanf("%d",&exm);
if(exm==)
se.insert(l); mp[l]=exm;
if(biao==)
l++;
else
l--;
}
if(strcmp(str,"POP")==)
{
if(biao==)
l--;
else
l++;
}
if(strcmp(str,"REVERSE")==)
{
if(biao==)
{
l--;
r--;
swap(l,r);
biao=;
}
else
{
l++;
r++;
swap(l,r);
biao=;
}
}
if(strcmp(str,"QUERY")==)
{
if(l==r)
printf("Invalid.\n");
else
{
if(biao==)
{
int exm;
int gg=;
for(it=se.begin(); it!=se.end(); it++)
{
if(*it>=r)
{
exm=*it;
gg=;
break;
}
}
if(exm>=l)/*评论区hack点 更正 */
gg=;
if(gg==)
{
if((l-r)%==)
printf("0\n");
else
printf("1\n");
}
else
{
if(l==r+)
printf("%d\n",mp[exm]);
else
{
if(exm==(l-))
exm--;
if((exm-r+)%)
printf("1\n");
else
printf("0\n");
}
}
}
else
{
int exm;
int gg=;
if(se.size()!=)
{
it=--se.end();
for(;; it--)
{
if(*it<=r)
{
exm=*it;
gg=;
break;
}
if(it==se.begin())
break;
}
}
if(exm<=l)/*评论区hack点 更正*/
gg=;
if(gg==)
{
if((r-l)%==)
printf("0\n");
else
printf("1\n");
}
else
{
int hhh=;
if(l==r-)
printf("%d\n",mp[exm]);
else
{
if(exm==(l+))
exm++;
if((r-exm+)%)
printf("1\n");
else
printf("0\n");
}
}
}
}
}
}
}
}
return ;
}
/*
2
6
PUSH 1
PUSH 1
PUSH 1
PUSH 1
REVERSE
QUERY
5
PUSH 1
PUSH 1
PUSH 1
PUSH 1
QUERY
*/
2016CCPC东北地区大学生程序设计竞赛1008/HDU 5929 模拟的更多相关文章
- 2016CCPC东北地区大学生程序设计竞赛 1008 HDU5929
链接http://acm.hdu.edu.cn/showproblem.php?pid=5929 题意:给你一种数据结构以及操作,和一种位运算,最后询问:从'栈'顶到低的运算顺序结果是多少 解法:根据 ...
- HDU 5925 Coconuts 【离散化+BFS】 (2016CCPC东北地区大学生程序设计竞赛)
Coconuts Time Limit: 9000/4500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Su ...
- HDU 5929 Basic Data Structure 【模拟】 (2016CCPC东北地区大学生程序设计竞赛)
Basic Data Structure Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth ...
- HDU 5926 Mr. Frog's Game 【模拟】 (2016CCPC东北地区大学生程序设计竞赛)
Mr. Frog's Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- HDU 5924 Mr. Frog’s Problem 【模拟】 (2016CCPC东北地区大学生程序设计竞赛)
Mr. Frog's Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
- HDU 5922 Minimum’s Revenge 【模拟】 (2016CCPC东北地区大学生程序设计竞赛)
Minimum's Revenge Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- HDU 5927 Auxiliary Set 【DFS+树】(2016CCPC东北地区大学生程序设计竞赛)
Auxiliary Set Time Limit: 9000/4500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tot ...
- 2016CCPC东北地区大学生程序设计竞赛 (2018年8月22日组队训练赛)
题目链接:http://acm.hdu.edu.cn/search.php?field=problem&key=2016CCPC%B6%AB%B1%B1%B5%D8%C7%F8%B4%F3%D ...
- 2016CCPC东北地区大学生程序设计竞赛 1005 HDU5926
链接http://acm.hdu.edu.cn/showproblem.php?pid=5926 题意:给我们一个矩阵,问你根据连连看的玩法可以消去其中的元素 解法:连连看怎么玩,就怎么写,别忘记边界 ...
随机推荐
- 用Navicat for MYsql创建表,插入中文显乱码
段都有编码设置.出现乱码肯定是你现在用的编码混乱造成的 解决办法: 第一步 先改数据库编码 先修改你的数据库,如果你页面用的是UTF-8编码那么你数据库内的编码也需要设置为UTF-8,每个字段都需要设 ...
- ionic build --release android
ionic bulid android ionic build --release android keytool -genkey -v -keystore demo.keystore -alias ...
- linux命令每日一练习-pwd,cd
pwd显示当前路径. pwd -P没能明白什么意思, cd 进入目录 cd ..返回上级目录
- Power Point已经检测到你的显卡可能无法正确配置
Microsoft PowerPoint打开ppt时提示信息 PowerPoint已检测到你的显卡可能无法正确配置最佳的幻灯片播放体验(“Power Point has detected that y ...
- 项目管理软件---redmine安装配置
redmine是一个开源的项目管理软件,其主页是:http://www.redmine.org redmine是基于Ruby on Rails框架的,跨平台和跨数据库. 安装过程 ========== ...
- Struts2 的ModelDriven理解
以UserAction为例,当UserAction实现了ModelDriven接口之后,与该接口相关的默认配置的拦截器会在拦截请求之后判断该请求是将要被UserAction处理而且UserAction ...
- UVa 10328 - Coin Toss (递推)
题意:给你一个硬币,抛掷n次,问出现连续至少k个正面向上的情况有多少种. 原题中问出现连续至少k个H的情况,很难下手.我们可以试着将问题转化一下. 设dp[i][j]表示抛掷i个硬币出现连续至多j个H ...
- SecureCRT下的串口无法输入
用串口配置交换机的时候,出现的问题: 用secureCRT建了一个串口COM1后,连接上开发板后,可以正确接受和显示串口的输出,但是按键输入无效. 解决方法: Session Options -> ...
- 【FreeBuf视频】《安全大咖说》专访知道创宇CTO杨冀龙(watercloud)
[FreeBuf视频]<安全大咖说>专访知道创宇CTO杨冀龙(watercloud) 发布于 2016/05/16 FreeBuF.COM 杨冀龙,江湖人称watercloud,知道创宇公 ...
- (转)iphone数据存储之-- Core Data的使用
原文:http://www.cnblogs.com/xiaodao/archive/2012/10/08/2715477.html iphone数据存储之-- Core Data的使用(一) 一. ...