Description
A chain of connected cells of two types A and B composes a cellular structure of some microorganisms of species APUDOTDLS.
If no mutation had happened during growth of an organism, its cellular chain would take one of the following forms:
simple stage O = A fully-grown stage O = OAB mutagenic stage O = BOA
Sample notation O = OA means that if we added to chain of a healthy organism a cell A from the right hand side, we would end up also with a chain of a healthy organism. It would grow by one cell A.
A laboratory researches a cluster of these organisms. Your task is to write a program which could find out a current stage of growth and health of an organism, given its cellular chain sequence.
Input
A integer n being a number of cellular chains to test, and then n consecutive lines containing chains of tested organisms.
Output
For each tested chain give (in separate lines) proper answers:
SIMPLE for simple stage FULLY-GROWN for fully-grown stage MUTAGENIC for mutagenic stage MUTANT any other (in case of mutated organisms)
If an organism were in two stages of growth at the same time the first option from the list above should be given as an answer.
Sample Input
4 A AAB BAAB BAABA
Sample Output
SIMPLE FULLY-GROWN MUTANT MUTAGENIC
分析:
题没有读懂,看样例也不知道什么意思,但没有放弃。只好问度娘。
新浪博客上有个大牛写的不错:
这题读的也不是太懂,但是AC了,按照自己的意思解释解释吧。就是说一个字符串转化为新字符串。有三种转化方式。第一种是从无到有产生一个A,第二种是在合法串后加一个AB(这种原串可以是空),第三种是在合法串前加一个B后面加一个A(原串不可为空)。判断这个串最后一步是哪种转化(首先回溯判断之前是否是不是每一步都是合法的转化)。语文表达能力有限。
看了之后醍醐灌顶,回溯判断。
代码:
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
char ch[100100];
int check(int L , int R)
{
if(L - 1 == R) return 0; //空串
if(L == R) return 1; //A 从无到有产生的A
else if(ch[R] == 'B' && ch[R - 1] == 'A') //***AB 合法串后加AB
{
if (check(L, R - 2) != 0) //剩下的串合法
return 2;
else //剩下的串不合法
return 0;
}
else if (ch[L] == 'B' && ch[R] == 'A') //B***A 合法串前加B后加A
{
if (check(L + 1, R - 1) != 0 )
return 3;
else
return 0;
}
return 0;
}
int main()
{
int n;
scanf("%d", &n);
while(n--) {
scanf("%s", ch);
int len = strlen(ch);
int k = check(0, len - 1);
if(k == 1) printf("SIMPLE\n");
else if(k == 2) printf("FULLY-GROWN\n");
else if(k == 3) printf("MUTAGENIC\n");
else printf("MUTANT\n");
}
return 0;
}