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 题意:给我们一个矩阵,问你根据连连看的玩法可以消去其中的元素 解法:连连看怎么玩,就怎么写,别忘记边界 ...
随机推荐
- css默认样式
html, address,blockquote,body, dd, div,dl, dt, fieldset, form,frame, frameset,h1, h2, h3, h4,h5, h6, ...
- mac 下隐藏和显示文件
显示:defaults write com.apple.finder AppleShowAllFiles -bool true隐藏:defaults write com.apple.finder Ap ...
- UI UIView
课程内容: 一.iOS概述 2007年1月9日Macworld大会上公布iPhone OS系统,2010WWDC大会上改名为iOS 二. UI编程概述 UI的本意是用户界面,是英文User和 ...
- 学好C++必须要注意的十八个问题
转自 http://blog.chinaunix.net/uid-7396260-id-2056691.html 一.#include "filename.h"和#i nclud ...
- Google search
filetype: active directory filetype: eg : lady gaga filetype:mp3 link: eg : link : supinfo.com(链接到su ...
- 分享第一次使用ProcessOn心得
最近朋友推荐了我一款在线作图工具ProcessOn,感受使用了几天感觉确实很不错,在这里给大家分享一下! ProcessOn应该算的上是第一款完全免费在线作图工具,之前用过国外有类似的,不过都是付费的 ...
- putty基本操作
1,进入全屏 标题栏右键,菜单中就有full screen选项. 2,退出全屏 鼠标移到左上角,单击鼠标左键,就会跳出菜单,full screen勾去掉. 3,从putty中复制内容到剪切板 鼠标左键 ...
- stm32定义GPIO口方向和操作的代码
#include "stm32f10x.h" #define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x2000000+(( ...
- 如何使用SVN管理我们的源代码
今天把公司的SVN服务器配置给做了一下,根据公司部门的不同,划分了不同的访问目录,并给不同目录配置了相应的权限,算是把这份差事给干完了,但其实我对自己的工作是不满意和有遗憾的,因为目前公司的SVN服务 ...
- tableviewcell的取消选中,高亮
1.取消多余cell的分割线 UIView *view = [UIView new]; view.backgroundColor = [UIColor clearColor]; [tableView ...