SGU191 这题题意太难懂，读了好久都没有理解。 题意： 有两个公司A、B，他们要展览物品，但是A公司的展柜要放B公司的物品，B公司的展柜要放A公司物品。最开始只有一个空柜台，从指定的一个公司开始，轮流进行操作，可选的操作有两个：①选一个自己公司的空展柜放上对方公司的物品 ②选一个自己公司的空展柜，在这个展柜左边插入一个对方公司的空展柜，再在这个新插入的展柜左边插入一个空展柜并放上自己公司的物品。 题中给出了一个最终物品摆放的序列，问最后物品摆放的序列能否和给定序列相同。 直接模拟，因为一开始只有一个A或B的空柜台， 按照目标序列，如果需要的和现在的空柜台相反就是1操作，相同就是2操作。相应增加和减少空柜台。 用一个栈来保存目前的柜台。

#### 191. Exhibition

time limit per test: 0.25 sec. memory limit per test: 4096 KB

input: standard input output: standard output

Two companies “A” and “B” decided to hold a joint exhibition of their production. Antitrust committee decided to take an experiment. To have a possibility to show its own production each company must advertise the production of its competitor. The exhibition is built as a straight row of stands. Some stands can be empty, other contain the production of represented companies (each stand can contain the production of only one company). The empty stands are also signed with the names of the companies. Originally the exhibition consists of just one empty stand, which is signed by the name of one of the companies (by a lot). The company can choose any of its empty stands and either to fill it with the production of the competitor or to place the empty stand to the left, signed by the name of the competitor, and to the left of that place the stand with its own production. If there are any stands to the left, they are moved to the left. By the beginning of the exhibition all stands must be filled. Your task is to write a program in accordance with the filled stands before the exhibition to determine if the requirements of the antitrust committee were satisfied or not.

Input

The first line contains the name of the company (“A” or “B”), which was chosen to be the first to fill the empty stand. The second line contains a row of the stands presented to the antitrust committee. The stands are listed from left to right. Letter “A” indicates a stand of company “A”, letter “B” - a stand of company “B”. Maximum number of stands at the exhibition is 30000.

Output

Output “YES” - if the requirements of the antitrust committee were fulfilled, and “NO” - if not.

Sample test(s)

Input

A AAB

Output

YES

[submit]

/* ***
Author :kuangbin
Created Time :2015/1/25 12:58:24
File Name :E:\2014ACM\SGU\SGU191.cpp
************************************************ */

#include <stdio.h>

#include <string.h>

#include

#include

#include

#include

#include

#include

#include

#include <math.h>

#include <stdlib.h>

#include <time.h>
using namespace std;
const int MAXN = 30010;
char str[MAXN];
int sta[MAXN];

int main()
{
//freopen(“in.txt”,”r”,stdin);
//freopen(“out.txt”,”w”,stdout);
while(scanf(“%s”,str) == 1){
int cnt = 0;
sta[0] = 1;
sta[1] = 0;
cnt = 1;
sta[cnt++] = 1-sta[cnt-1];
printf(“%d\n”,sta[1]);
cnt = 0;
sta[cnt++] = (str[0]==’B’);
scanf(“%s”,str);
int len = strlen(str);
int i = 0;
while(i < len && cnt > 0){
if(sta[cnt-1] == (str[i]==’A’))cnt–;
else {
sta[cnt++] = (str[i]==’A’);
}
i++;
}
if(i == len && cnt == 0)printf(“YES\n”);
else printf(“NO\n”);
}
return 0;
}

------ 本文结束------
• 本文作者： kuangbin
• 本文链接： 564.html
• 版权声明： 本博客所有文章除特别声明外，均采用 CC BY-NC-SA 4.0 许可协议。转载请注明出处！
0%