Uva--620(动规)
2014-08-02 16:23:46
Cellular Structure |
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
思路:按几种生长方式从两边向中间逼近,直到一个字符为止。
1 /************************************************************************* 2 > File Name: g.cpp 3 > Author: Nature 4 > Mail: 564374850@qq.com 5 > Created Time: Wed 30 Jul 2014 08:35:57 PM CST 6 ************************************************************************/ 7 8 #include <cstdio> 9 #include <cstring> 10 #include <cstdlib> 11 #include <cmath> 12 #include <iostream> 13 #include <algorithm> 14 using namespace std; 15 16 int n; 17 char s[10005]; 18 19 int Solve(int x,int y){ 20 if(x > y) 21 return 4; 22 if(x == y && s[x] == 'A') 23 return 1; 24 //simple 25 if(y > 0 && s[y - 1] == 'A' && s[y] == 'B' && Solve(x,y - 2) != 4) 26 return 2; 27 else if(s[x] == 'B' && s[y] == 'A' && Solve(x + 1,y - 1) != 4) 28 return 3; 29 return 4; 30 } 31 32 int main(){ 33 scanf("%d",&n); 34 while(n--){ 35 scanf("%s",s); 36 int len = strlen(s); 37 int ans = Solve(0,len - 1); 38 if(ans == 1) 39 printf("SIMPLE\n"); 40 else if(ans == 2) 41 printf("FULLY-GROWN\n"); 42 else if(ans == 3) 43 printf("MUTAGENIC\n"); 44 else 45 printf("MUTANT\n"); 46 } 47 return 0; 48 }