poj1363 栈入门题·
来源:互联网 发布:买家淘宝客怎么用 编辑:程序博客网 时间:2024/06/06 18:03
题目链接:http://poj.org/problem?id=1363
思路:使用一个栈(in) 用来存储已经进入车站的火车
依次读取火车出栈顺序的序列 如果与栈的顶部元素相同 弹出栈顶部元素 读取下一个出栈顺序
如果不同 下一辆火车进栈 如果火车全部进栈而出栈顺序序列未读完 说明不能按顺序出栈 则补满 读取出栈顺序的序列
如果出栈顺序序列读完 跳出循环 若栈为空 则yes ; else,no;
注意输出 空行
//memory 708k time 79ms#include <cstdio>#include <algorithm>#include <stack>#include <iostream>using namespace std;int main(){ int t; while(scanf("%d",&t),t){ if(t==0) break; while(true){ stack<int> in; //声明为成员变量 不用初始清空 int index=1; in.push(index); int i=1; int temp; scanf("%d",&temp); if(temp==0) break; while(true){ if(!in.empty()&&in.top()==temp){ in.pop(); i++; if(i>t) break; scanf("%d",&temp); }else{ index++; if(index>t){ while(true){ //此处为当进栈的火车已满而 读取出栈顺序次数未到时 i++; //补满 出栈顺序次数 if(i>t) break; scanf("%d",&temp); } } if(i>t) break; in.push(index); } } if(in.empty()) printf("Yes\n"); else printf("No\n"); } printf("\n"); //空行 } return 0;}
- poj1363 栈入门题·
- poj1363(栈的入门)(一)
- poj1363----栈
- POJ1363【栈】
- 【POJ1363】栈
- POJ1363--Rails--栈
- POJ1363-栈应用
- 1poj1363(栈)
- poj1363-栈与数组
- poj1363(栈的应用)
- POJ1363 Rails【stack】【栈】
- POJ1363 Rails(栈)
- POJ1363 Rails(数据结构栈)
- poj1363 Rails(栈模拟)
- POJ1363:Rails(栈)
- 【栈】POJ1363-Rails
- POJ1363 Rails【单调栈】
- POJ1363 Rails 栈+模拟
- hdu 4714 Tree2cycle
- SilkTest FAQ 8
- Android graphics学习笔记(1) - Color
- H2 DataBase 数据库操作
- C++语言中multiset的相关用法及扩展
- poj1363 栈入门题·
- 回顾总结64位CentOs下安装QT遇到的问题和解决方法
- Partition X does not end on cylinder boundary
- java 简单的字节流与字符串的转换换 及加密与解密(对称)
- 移动设计空间节省之道
- MySQL性能优化的最佳20+套经验
- 在局域网中开放ORACLE服务
- consistent read--一致性读--Logical read-逻辑读-current read当前读--物理读示例
- 最优化方法在图像处理中的应用【3】