ZOJ3202-Second-price Auction(根据输入输出判断是队列还是栈)
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu
Description
Do you know stack and queue? They're both important data structures. A stack is a "first in last out" (FILO) data structure and a queue is a "first in first out" (FIFO) one.
Here comes the problem: given the order of some integers (it is assumed that the stack and queue are both for integers) going into the structure and coming out of it, please guess what kind of data structure it could be - stack or queue?
Notice that here we assume that none of the integers are popped out before all the integers are pushed into the structure.
Input
There are multiple test cases. The first line of input contains an integer T (T <= 100), indicating the number of test cases. Then T test cases follow.
Each test case contains 3 lines: The first line of each test case contains only one integer N indicating the number of integers (1 <= N <= 100). The second line of each test case contains N integers separated by a space, which are given in the order of going into the structure (that is, the first one is the earliest going in). The third line of each test case also contains N integers separated by a space, whick are given in the order of coming out of the structure (the first one is the earliest coming out).
Output
For each test case, output your guess in a single line. If the structure can only be a stack, output "stack"; or if the structure can only be a queue, output "queue"; otherwise if the structure can be either a stack or a queue, output "both", or else otherwise output "neither".
Sample Input
4
3
1 2 3
3 2 1
3
1 2 3
1 2 3
3
1 2 1
1 2 1
3
1 2 3
2 3 1
Sample Output
stack
queue
both
neither 利用栈和队列的性质判断就好
#include<cstdio>
#include<string>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<cstring>
#include<set>
#include<queue>
#include<algorithm>
#include<vector>
#include<map>
#include<cctype>
#include<stack>
#include<sstream>
#include<list>
#include<assert.h>
#include<bitset>
#include<numeric>
#define max_v 105
#define eps 10e-6
using namespace std;
int a[max_v];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
for(int i=;i<n;i++)
scanf("%d",&a[i]);
int x;
int isque=;
int isstack=;
for(int i=;i<n;i++)
{
scanf("%d",&x);
if(a[i]!=x)
isque=;
if(x!=a[n-i-])
isstack=;
}
if(isque&&isstack)
printf("both\n");
else if(isque==&&isstack==)
printf("queue\n");
else if(isque==&&isstack==)
printf("stack\n");
else if(isque==&&isstack==)
printf("neither\n");
}
return ;
}
ZOJ3202-Second-price Auction(根据输入输出判断是队列还是栈)的更多相关文章
- codeforces Rockethon 2015 C Second price auction [想法]
传送门 C. Second price auction time limit per test 2 seconds memory limit per test 256 megabytes input ...
- 链表回文串判断&&链式A+B
有段时间没有练习了,链表回文串判断用到了栈.链式A+B将没有的项用0补充.链表有没有头节点,及结点和链表的区别,即pNode和pHead. //#include<iostream> //u ...
- 链表回文串判断&&链式A+B
有段时间没有练习了,链表回文串判断用到了栈.链式A+B将没有的项用0补充.链表有没有头节点,及结点和链表的区别,即pNode和pHead. //#include<iostream> //u ...
- python判断栈的弹出序列是否合法
参考:https://www.2cto.com/kf/201701/552515.html 数据结构之判断栈的弹出序列是否合法:输入两个整数序列,第一个序列表示栈的压入序列,请判断第二个序列是否为该栈 ...
- ECShop函数列表大全
lib_time.php gmtime() P: 获得当前格林威治时间的时间戳 /$0 server_timezone() P: 获得服务器的时区 /$0 local_mktime(hour=NULL ...
- ECSHOP二次开发指南
ECSHOP二次开发指南 发布时间:2013-05-28 12:47:00 来源: 评论:0 点击: 次 [字号:大 中 小] QQ空间新浪微博腾讯微博人人网豆瓣网百度空间百度搜藏开心网复制更 ...
- echo二次开发 ecshop 函数列表
lib_time.php (时间函数) gmtime() P: 获得当前格林威治时间的时间戳 /$0 server_timezone() P: 获得服务器的时区 /$0 local_mktime($h ...
- ecshop 函数列表大全
lib_time.phpgmtime() P: 获得当前格林威治时间的时间戳 /$0server_timezone() P: 获得服务器的时区 /$0local_mktime($hour = NULL ...
- ABAP技术总结
SAP ——ABAP/4 技术总结 V3.0 2014-10-14 --江正军 1. 1.1. 1.1.1. 1.2. 1.3. 1.4. 1.5. 1.6. 1.7. 1.7.1. 1.7.2. ...
随机推荐
- SQL NVARCHAR和VARCHAR限制
1:NVARCHAR(max)可以存储(有时甚至更多)2GB的数据(10亿个双字节字符). 2:NVARCHAR和VARCHAR连接时的截断取决于数据类型 varchar(n) + varchar(n ...
- thinkPHP3.2.2 控制器内跳转的三种方式
public function jump() { $obj = new TestController(); $obj->logged(); } public function jump1() { ...
- 用jquery实现带左右按键的轮播图
成品如下: 简单来说就是点击“右”按钮时,转换到右边的下一幅图片,同时上面的小方块颜色也跟着改变,如果已经是最后一幅图片,再点击“右”,则转换到第一幅图片,是直接向左移找到第一幅图的,明天再做一下无缝 ...
- 微格式(microformat)
由于HTML中缺少相应的元素,很难突出显示人.地点或日期等类型的信息.为了解决这个问题,有一组开发人员决定开发一套标准的命名约定盒标记模式来表示这些数据.这些命名约定基于vCard和iCalendar ...
- solidity 语法学习
基于 cryptozombies.io ZombieFactory pragma solidity ^0.4.19; contract ZombieFactory { // 事件, web3.js 可 ...
- Pwn with File结构体(四)
前言 前面几篇文章说道,glibc 2.24 对 vtable 做了检测,导致我们不能通过伪造 vtable 来执行代码.今天逛 twitter 时看到了一篇通过绕过 对vtable 的检测 来执行代 ...
- 润乾填报页面导入excel后增加js动作
当页面从excel中导入数据之后,自动加入js的检查功能,下面是如何在导入excel后直接引入js的功能实例: var _orgImportExcel = report1_importExcel ...
- Storm并行度
1.Storm并行度相关的概念 Storm集群有很多节点,按照类型分为nimbus(主节点).supervisor(从节点),在conf/storm.yaml中配置了一个supervisor有多个槽( ...
- 《SQL Server 2008从入门到精通》--20180628
数据库基本概念:区.页.行 区:SQL Server中管理空间的基本单位.一个区大小为64KB,是八个物理上连续的页.SQL Server中每MB有16个区.一旦一个区被存储满,SQL Server将 ...
- 转载:eclipse 搭建SSH项目(第一篇)
第一篇:原文地址:http://blog.csdn.net/aaaaaaaa0705/article/details/6288431(虽然没有具体的例子,不过逻辑性强点,比较容易看懂) SSH框架是最 ...