首页 > 其他 > 详细

火车进出站(POJ1363)

时间:2016-04-20 21:55:47      阅读:123      评论:0      收藏:0      [点我收藏+]

题目链接:http://poj.org/problem?id=1363

 

技术分享

 

技术分享
#include <stdio.h>
#include <stack>

using namespace std;

int ans[10000]; ///出栈秩序

int main()
{
    int t;  ///有多少车厢
    while(scanf("%d",&t),t)
    {
        stack<int>s;
        while(scanf("%d",&ans[0]),ans[0])
        {
            for(int i=1;i<t;i++)
                scanf("%d",&ans[i]);

            ///模拟进栈
            int k,i;
            for(i=1,k=0;i<=t;i++)
            {
                s.push(i);
                while(s.top()==ans[k])
                {
                    if(!s.empty()) s.pop();
                    k++;
                    if(s.empty()) break;
                }
            }
            if(k==t) printf("Yes\n");
            else printf("No\n");
        }
        printf("\n");
    }

    return 0;
}
View Code

 

火车进出站(POJ1363)

原文:http://www.cnblogs.com/TreeDream/p/5414430.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!