码迷,mamicode.com
首页 > 其他好文 > 详细

Codevs 2821 天使之城

时间:2016-12-24 09:32:58      阅读:102      评论:0      收藏:0      [点我收藏+]

标签:ddl   pull   style   block   lock   空间   字符串   printf   scan   

2821 天使之城

 时间限制: 1 s    空间限制: 128000 KB     题目等级 : 黄金 Gold
题目描述 Description

天使城有一个火车站,每辆火车都从A方向驶入车站,
再从B方向驶出车站。

 

为了调度火车,火车站设有停放轨道,可存放5辆火车。已知从A进入车站顺序为1、2、3……。现在给你一个调度方案,判断是否可行,如果可行,输出出站顺序。
有以下几种调度方法:
A. 将A上的头一辆车驶出B方向
B. 将A上的头一辆车停入暂停轨道
C. 将暂停轨道上最外面的车驶出B方向

输入描述 Input Description

输入第一行一个整数N(n<30)表示调度方案步骤数目。
下一行一个字符串,有N个大写字母,表示调度方法。

输出描述 Output Description

输出若不可行(暂停站满了还停车、暂停站空了还出车),则输出一行“No”。
若可行,输出一行“Yes”,再输出若干行,每行一个整数,表示车出站序列。

样例输入 Sample Input

[样例输入1]
6
ABBCCA
[样例输入2]
5
BACAC

 

样例输出 Sample Output

[样例输出1]
Yes
1
3
2
4
[样例输出2]
No

数据范围及提示 Data Size & Hint

如题

 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 int n,stack[10025],top,cnt=1,cur=1,dui[10025];
 5 char s[10025];
 6 int main()
 7 {
 8     scanf("%d",&n);
 9     scanf("%s",s+1);
10     for(int i=1;i<=n;i++)
11     {
12         if(s[i]==C&&top==0) { printf("No\n");return 0; }
13         if(top>5) { printf("No\n");return 0; }
14         if(s[i]==A){ dui[cur]=cnt;cnt++;cur++; }
15         if(s[i]==B){ stack[++top]=cnt;cnt++; }
16         if(s[i]==C){ dui[cur]=stack[top];top--;cur++; }
17     }
18     printf("Yes\n");
19     for(int i=1;i<cur;i++)
20     {
21         printf("%d\n",dui[i]);
22     }
23     return 0;
24 }

 

Codevs 2821 天使之城

标签:ddl   pull   style   block   lock   空间   字符串   printf   scan   

原文地址:http://www.cnblogs.com/suishiguang/p/6216631.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!