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. ...
随机推荐
- MySql基本学习知识点:
1.Mysql的简介: (1):常识: MySQL是一种关系数据库管理系统,是一种开源软件 由瑞典MySQL AB公司开发,2008年1月16号被Sun公司收购.2009年,SUN又被Oracle收购 ...
- Anaconda多环境多版本python配置笔记
一.Conda测试过程: 使用conda.首先确认已经安装好了conda 配置环境.下一步通过创建几个环境来展示conda的环境管理功能.学习如何确认在哪个环境中,以及如何做复制一个环境作为备份. 测 ...
- sql中 设置区分大小写
CI 指定不区分大小写,CS 指定区分大小写alter table 表名 alter column 字段 nvarchar(100) collate chinese_prc_cs_as --区分大小写 ...
- Ubuntu pydot failed to call GraphViz.Please install GraphViz 解决方法
如果遇到: OSError: `pydot` failed to call GraphViz.Please install GraphViz (https://www.graphviz.org/) a ...
- Android获取SD卡路径及SDCard内存的方法
这篇文章主要介绍了Android获取SD卡路径及SDCard内存的方法,较为详细的分析了Android针对SD卡操作所涉及的类及其具体函数功能,非常具有实用价值,需要的朋友可以参考下 本文实例讲述了A ...
- android studio使用openssl
前言 逆向的基础是开发, 逆向分析时很多时候会使用一些公开的加密函数来对数据进行加密,通过使用 openssl 熟悉下. 正文 首先得先编译出来 openssl,然后把它们复制到你的工程目录下. in ...
- Pwn with File结构体(二)
前言 本文由 本人 首发于 先知安全技术社区: https://xianzhi.aliyun.com/forum/user/5274 最新版的 libc 中会对 vtable 检查,所以之前的攻击方式 ...
- Object、String、数组的 toString() 方法和 equals() 方法及java.util.Arrays
public class Test { public static void main(String[] args) { int[] a = {1, 2, 4, 6}; int[] b = a; in ...
- 解决js跨域
这里说的js跨域是指通过js在不同的域之间进行数据传输或通信,比如用ajax向一个不同的域请求数据,或者通过js获取页面中不同域的框架中(iframe)的数据.只要协议.域名.端口有任何一个不同,都被 ...
- 设计多选按钮ListChooseView
设计多选按钮ListChooseView 答应某位女屌丝而写的控件,效果还不错,开源给大家^_^! 效果图: 源码: // // ListChooseView.h // ScrollChooseBut ...