【poj】1363-Rails
来源:互联网 发布:php图片一句话木马 编辑:程序博客网 时间:2024/05/01 18:41
#include <iostream>#include <stdio.h>#include <memory.h>const int MAXSIZE = 10000;using namespace std;int trains[MAXSIZE];int orders[MAXSIZE];int stacks[MAXSIZE];int top;int main(){// freopen("b:\\acm\\input.txt","r",stdin); int n,m,mount; bool bFin = true; bool bEnd = false; bool bFinput = true; while( scanf("%d",&mount) != EOF ) { bool bFound = true; int j = 0; memset(trains,MAXSIZE,0); memset(orders,MAXSIZE,0); memset(stacks,MAXSIZE,0); top = 0; if( mount == 0) { bFin = true; if(bEnd) return 0; else bEnd = true; // cout << endl; continue; } bEnd = false; if(bFin) { if(bFinput) { bFinput = false; } else { cout << endl; } n = mount;; for(int i = 0; i < n ; i++) { trains[i] = i+1; cin >> orders[i]; } bFin = false; } else { orders[0] = mount; trains[0] = 1; for(int i = 1 ; i < n; i++) { trains[i] = i+1; cin >> orders[i]; } } //trains 1 2 3 4 5 6... //orders 6 5 4 3 2 1... for(int i = 0 ; i < n ; i++) { //思路: //检查trains和stack中元素,如果 //trains中没有元素与orders[i]相等 //并且stack[top] != orers[i],No j = 0; /////This causes wrong answer if(orders[i] == stacks[top-1]) { stacks[top - 1] = 0; top--; if(i != n-1) continue; else { cout << "Yes" << endl; continue; } } while( (orders[i] != trains[j]) && (j < n) ) { if(trains[j] != 0) stacks[top++] = trains[j]; trains[j] = 0; j++; } if( (stacks[top-1] != orders[i]) && (trains[j] != orders[i])) { cout << "No" << endl; break; } else { if(stacks[top-1] == orders[i]) { stacks[top-1] = 0; top--; } if(trains[j] == orders[i]) { trains[j] = 0; } if(i == n-1) cout << "Yes" << endl; } } } return 0;}
题目地址:
http://poj.grids.cn/practice/1363/
- Poj 1363 Rails
- 【poj】1363-Rails
- POJ 1363 Rails
- [poj] 1363 Rails
- poj 1363(Stack ) Rails
- poj,1363,Rails
- poj-1363-Rails(栈)
- poj 1363 Rails
- poj 1363 Rails
- poj 1363 Rails
- POJ - 1363 Rails
- POJ 1363 Rails
- poj-1363-rails
- [置顶]poj-1363Rails
- POJ-1363 Rails
- POJ 1363 Rails
- OpenJudg / Poj 1363 Rails
- POJ 1363 Rails
- hdoj 1615
- 菜鸟学iPhone开发-计算器实例
- iphone开发笔记(-) 退回输入键盘:自定义颜色:隐藏状态栏:
- 开博
- field module的on input和on request区别
- 【poj】1363-Rails
- Iphone SDK 实例--新手必读
- LHF Objective-C语法(9)内存管理
- Delete 多态类数组
- mysqlnd cannot connect to MySQL 4.1+ using the old insecure authentication
- c讀取文本文件並將單詞存入數組排序輸出
- 用WTL的文件对话框打开图片,D3D渲染
- 关于标准c中的strtok和linux库里面的strsep
- 学习ACE