【栈】 poj 1363
poj1363,这道题是数据结构与算法中的经典问题,给定一组进栈顺序,问栈有多少种出去的顺序。
#include<stdio.h>
#include <stack>
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
// freopen("in.txt","r",stdin);
int n;
while(scanf("%d",&n)&&n)
{
stack<int> sta;
],i;
]))
{
while(!sta.empty()) sta.pop();
]==)
{
putchar('\n');break;}
; i<n; i++)
scanf("%d", &s[i]);
;
;i<=n;)
{
while(sta.empty()||(!sta.empty()&&sta.top()<s[j]))
{
sta.push(i++);
}
while(!sta.empty() && sta.top()==s[j])
{
j++;sta.pop();
}
if(!sta.empty() && j<n && sta.top()>s[j])break;
}
if(sta.empty()==true) cout <<"Yes" << endl;
else cout << "No" << endl;
}
}
;
}
【栈】 poj 1363的更多相关文章
- POJ 1363 Rails(栈)
题目代号:POJ 1363 题目链接:http://poj.org/problem?id=1363 题目原题: Rails Time Limit: 1000MS Memory Limit: 100 ...
- POJ 1363 Rails(栈)
思路:将出车站的顺序存入数组train,由于入车站的顺序是固定的,为1~N,所以用P表示进站的车,初始为1. 接下来举例说明吧: 原来入站顺序: 1 2 3 4 5 读入的出战顺序: 3 4 2 ...
- poj 1363 Rails in PopPush City &&【求堆栈中合法出栈顺序次数】
问题如下: 问题 B: Rails 时间限制: Sec 内存限制: MB 提交: 解决: [提交][状态][讨论版] 题目描述 There is a famous railway station in ...
- poj 1363 火车进站 (栈的应用)
Description There is a famous railway station in PopPush City. Country there is incredibly hilly. Th ...
- poj 1363 Rails (【栈的应用】 刘汝佳的写法 *学习)
Rails Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 25964 Accepted: 10199 Descripti ...
- poj 1363 Rails 解题报告
题目链接:http://poj.org/problem?id=1363 题意:有一列火车,车厢编号为1-n,从A方向进站,向B方向出站.现在进站顺序确定,给出一个出站的顺序,判断出站顺序是否合理. 实 ...
- OpenJudg / Poj 1363 Rails
1.链接: http://poj.org/problem?id=1363 http://bailian.openjudge.cn/practice/1363 2.题目: Rails Time Limi ...
- [欧拉回路+手动开栈] poj 1780 Code
题目链接: http://poj.org/problem? id=1780 Code Time Limit: 1000MS Memory Limit: 65536K Total Submissio ...
- poj 1363
这是一道数据结构的问题,用到了栈的知识.题目大意讲的是每一次有N辆车从A到B,但是要将车辆的顺序重新排列,可以通过中转站C来辅助排列,但是C符合先进后出的原则,这一点和栈的特性相同. 整个重新排序的过 ...
随机推荐
- 简单的setInterval应用
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- VC++中使用ADO方式操作ACCESS数据库
ADO(ActiveX Data Object)是Microsoft数据库应用程序开发的新接口,是建立在OLE DB之上的高层数据库访问技术,即使你对OLE DB,COM不了解也能轻松对付ADO,因为 ...
- LD_LIBRARY_PATH vs LIBRARY_PATH
LIBRARY_PATH is used by gcc before compilation to search for directories containing libraries that n ...
- Java 环境搭建的一些问题
1.http://www.eclipse.org/webtools/ eclipse 官网,SE.EE方向是两个不同eclipse 2.tomcat 对eclipse来说是一个插件,需要额外下载 T ...
- .net项目svn项目管理文件清单
You can add the following files to Visual Studio source control: Solution files (*.sln). Project fil ...
- ueditor浏览器 无法上传文件.问题
dll也都引用了 路径绝对tmd没问题 最后 我一点一点的调试发现了问题 草tmd百度程序员 */UE.ajax = function() { //创建一个ajaxRequest对象 var fnSt ...
- php获取当前文件绝对路径
php如何获取当前文件的绝对路径. dirname(__FILE__) 函数返回的是脚本所在在的路径 <?php $basedir = dirname(__FILE__); echo $base ...
- JSP精华知识点总结
本文转自:http://blog.csdn.net/qy1387/article/details/8050239 JSP精华知识点总结 Servlet三个要素 1.必须继承自HttpServlet 2 ...
- make TARGET_PRODUCT=am335xevm OMAPES=4.x rowboat_clean 出现sgx相关的错误
这些错误是一些链接错误,由于地址变更导致的软链接不对.所以只要更改下软链接的具体地址就可以.
- 为什么要在onNewIntent的时候要显示的去调用setIntent
一.原因: 当调用到onNewIntent(intent)的时候,需要在onNewIntent() 中使用setIntent(intent)赋值给Activity的Intent.否则,后续的getIn ...