题目

链接:https://ac.nowcoder.com/acm/contest/28537/D
来源:牛客网

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 32768K,其他语言65536K
64bit IO Format: %lld

题目描述

There is a famous railway station in PopPush City. Country there is incredibly hilly. The station was built in last century. Unfortunately, funds were extremely limited that time. It was possible to establish only a surface track. Moreover, it turned out that the station could be only a dead-end one (see picture) and due to lack of available space it could have only one track.

The local tradition is that every train arriving from the direction A continues in the direction B with coaches reorganized in some way. Assume that the train arriving from the direction A has N <= 1000 coaches numbered in increasing order 1, 2, …, N. The chief for train reorganizations must know whether it is possible to marshal coaches continuing in the direction B so that their order will be a1, a2, …, aN. Help him and write a program that decides whether it is possible to get the required order of coaches. You can assume that single coaches can be disconnected from the train before they enter the station and that they can move themselves until they are on the track in the direction B. You can also suppose that at any time there can be located as many coaches as necessary in the station. But once a coach has entered the station it cannot return to the track in the direction A and also once it has left the station in the direction B it cannot return back to the station.

Input
The input consists of blocks of lines. Each block except the last describes one train and possibly more requirements for its reorganization. In the first line of the block there is the integer N described above. In each of the next lines of the block there is a permutation of 1, 2, …, N. The last line of the block contains just 0.

The last block consists of just one line containing 0.

输入描述:

The input consists of blocks of lines. Each block except the last describes one train and possibly more requirements for its reorganization. In the first line of the block there is the integer N described above. In each of the next lines of the block there is a permutation of 1, 2, ..., N. The last line of the block contains just 0.
The last block consists of just one line containing 0.

输出描述:

The output contains the lines corresponding to the lines with permutations in the input. A line of the output contains Yes if it is possible to marshal the coaches in the order required on the corresponding line of the input. Otherwise it contains No. In addition, there is one empty line after the lines corresponding to one block of the input. There is no line in the output corresponding to the last ``null'' block of the input.

示例1

输入

5
1 2 3 4 5
5 4 1 2 3
0
6
6 5 4 3 2 1
0
0

输出

Yes
No Yes

题解

这道题目其实不难,重点是输入以及输出有大大的问题

代码

#include <iostream>
#include <stack>
using namespace std;
int s[1005];
int n = 0;
bool check()
{
int j = 0;
stack<int> a;
for (int i = 1; i <= n; i++)
{
a.push(i);
while (!a.empty() && a.top() == s[j])
{
a.pop();
j++;
}
}
if (a.empty())
{
return true;
}
else
return false;
}
int main()
{
int flags = 0;
int buf = 0;
while (1)
{
cin >> buf;
if (!buf)
break;
else
{
n = buf;
if (flags)
cout << endl;
} while (1)
{
cin >> buf;
if (buf)
{
s[0] = buf;
for (int i = 1; i < n; i++)
cin >> s[i];
flags = 1;
if (check())
cout << "Yes" << endl;
else
cout << "No" << endl;
}
else
break;
}
}
return 0;
}

Rails_via牛客网的更多相关文章

  1. 牛客网 --java问答题

    http://www.nowcoder.com/ 主要是自己什么都不怎么会.在这里可以学习很多的! 第一天看题自己回答,第二天看牛客网的答案! 1 什么是Java虚拟机?为什么Java被称作是“平台无 ...

  2. 牛客网《BAT面试算法精品课》学习笔记

    目录 牛客网<BAT面试算法精品课>学习笔记 牛客网<BAT面试算法精品课>笔记一:排序 牛客网<BAT面试算法精品课>笔记二:字符串 牛客网<BAT面试算法 ...

  3. C++版 - HDUoj 2010 3阶的水仙花数 - 牛客网

    版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C++版 - ...

  4. 牛客网第9场多校E(思维求期望)

    链接:https://www.nowcoder.com/acm/contest/147/E 来源:牛客网 题目描述 Niuniu likes to play OSU! We simplify the ...

  5. 牛客网暑期ACM多校训练营(第七场)Bit Compression

    链接:https://www.nowcoder.com/acm/contest/145/C 来源:牛客网 题目描述 A binary string s of length N = 2n is give ...

  6. Beautiful Numbers(牛客网)

    链接:https://ac.nowcoder.com/acm/problem/17385来源:牛客网 题目描述 NIBGNAUK is an odd boy and his taste is stra ...

  7. 牛客网华为机试题之Python解法

    牛客网华为机试题之Python解法 第1题 字符串最后一个单词的长度 a = input().split(" ") print(len(a[-1])) 第2题 计算字符个数 a = ...

  8. 牛客网Wannafly挑战赛25A 因子(数论 素因子分解)

    链接:https://www.nowcoder.com/acm/contest/197/A来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言5242 ...

  9. 牛客网 2018年东北农业大学春季校赛 L题 wyh的天鹅

    链接:https://www.nowcoder.com/acm/contest/93/L来源:牛客网 时间限制:C/C++ 3秒,其他语言6秒空间限制:C/C++ 262144K,其他语言524288 ...

随机推荐

  1. 你不知道的JS 中——yield

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. 使用C#跨PC 远程调用程序并显示UI界面

    在项目中有一个需求是需要在局域网内跨PC远程调用一个程序,并且要求有界面显示,调查了一些资料,能实现远程调用的.Net技术大概有PsExec.WMI.Schedule Task. 这三种方式都做了一个 ...

  3. 树莓派开发笔记(十四):入手研华ADVANTECH工控树莓派UNO-220套件(三):使用研发自带系统测试rtc、gpio、232和485套件接口

    前言   上一篇说明了必须要使用研华自带的8G卡的系统,通过沟通拿到了相关的系统,购买的时候会带8GB的卡,请自行备份一份镜像.本篇对uno-220套件的相关研华配套的额外接口做测试,篇幅较长,重点讲 ...

  4. Vulnhub-earth

    1.信息收集 1.1找到目标主机ip vulnhub靶场通用的技巧 这里我们靶场是nat模式的 所以肯定就是在我们自己设置的一个网段范围内,我这里nat本机的地址是10.1.1.1 所处的网段就是10 ...

  5. 分布式任务调度ScheduleMaster

    1.什么是ScheduleMaster ScheduleMaster是分布式任务调度系统.简称:集中任务调度系统,最简单的理解ScheduleMaster,就是对不同的系统里面的调度任务做统一管理的框 ...

  6. Docker运行资源控制

    概述 ​ 一个 docker host 上会运行若干容器,每个容器都需要 CPU.内存和 IO 资源.对于 KVM,VMware 等虚拟化技术,用户可以控制分配多少 CPU.内存资源给每个虚拟机.对于 ...

  7. linux运维基础1

    内容概要 运维简介 运维岗位职责 服务器 服务器硬件介绍 磁盘阵列 虚拟化软件及环境 虚拟化软件 安装操作系统 Vmware虚拟机安装及相关配置流程 内容详情 运维简介 运维岗位职责 核心:运行维护应 ...

  8. Linux系统下运行.sh文件

    在Linux系统下运行.sh文件有两种方法,比如我在root目录下有个vip666.sh文件 #chmod +x *.sh的文件名 #./*.sh的文件名 第一种(这种办法需要用chmod使得文件具备 ...

  9. 编程式导航路由跳转到当前路由(参数不变), 多次执行会抛出NavigationDuplicated的警告错误?

    注意:编程式导航(push|replace)才会有这种情况的异常,声明式导航是没有这种问题,因为声明式导航内部已经解决这种问题. 这种异常,对于程序没有任何影响的. 为什么会出现这种现象: 由于vue ...

  10. 树莓派开发笔记(十七):树莓派4B+上Qt多用户连接操作Mysql数据库同步(单条数据悲观锁)

    前言   安装了mysq数据库,最终时为了实现在一个树莓派上实现多用户多进程操作的同步问题,避免数据并发出现一些错误,本篇安装了远程服务并且讲述了使用Qt进行悲观锁for update操作,命令行进行 ...