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 题意:给我们一个矩阵,问你根据连连看的玩法可以消去其中的元素 解法:连连看怎么玩,就怎么写,别忘记边界 ...
随机推荐
- POJ 2528 区间染色,求染色数目,离散化
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 47905 Accepted: 13903 ...
- 在JavaScript 自定义对象来模拟Java中的Map
直接看代码: //模拟一个Map对象 function Map(){ //声明一个容器 var container={}; //定义一个put方法,向容器中存值 this.put=function(k ...
- 向MySql中插入中文时出现乱码
这个因为字符集编码问题.在连接字符串中加上CharSet=gbk
- nginx查看配置文件nginx.conf路径
当你执行 nginx -t 得时候,nginx会去测试你得配置文件得语法,并告诉你配置文件是否写得正确,同时也告诉了你配置文件得路径: # nginx -t nginx: the configu ...
- 第48套题【tarjan】【图&树的连通性】【并查集】
Problem 1 图的连通性
- Java并发编程(三)后台线程(Daemon Thread)
后台线程,守护线程(Daemon Thread) 所谓的后台线程,就是指这种线程并不属于程序中不可或缺的部分,因此当所有的非后台线程结束时,程序也就终止了,同时会杀死进程中的所有后台线程.通过setD ...
- struts中拦截器的开发
1.开发Interceptor类 用户自定义的拦截器一般需要继承AbstractInterceptor类,重写intercept方法 public class UserInterceptor exte ...
- SharePoint 2013 开发——CSOM概要
博客地址:http://blog.csdn.net/FoxDave 本篇对客户端API做一个大致地了解. 看一下各个类别主要API之间的对应关系表. 假设我们对Server API已经有了足够地了 ...
- 移动设备和SharePoint 2013 - 第1部分:概述
博客地址:http://blog.csdn.net/foxdave 原文地址 在该系列文章中,作者展示了SharePoint 2013最显著的新功能概观--对移动设备的支持. 该系列文章: 移动设备和 ...
- 使用windows远程桌面连接Windows Azure中的Ubuntu虚拟机
1.创建ubuntu虚拟机,这里同样不再赘述,创建过程和创建Windows虚拟机基本一样,只是登录可以选择密钥注入或者用户名密码(为了方便我选择了用户名密码认证),创建完成后,查看虚拟机详情中的端口信 ...