/*
初始化细胞为A(SIMPLE),细胞生长方式有3种
1)右边加AB(FULLY-GROWN)
2) 左边加B,右边加A(MUTAGENIC)
3)变异生长,细胞序列不确定(MUTANT)
个人理解:
1)一旦细胞变异生长,细胞的状态就一直是变异状态
2)细胞的生长方式会变化
算法:
1) 如果序列为A,当前状态为SIMPLE
2) 如果序列为xxxAB, 如果xxx的状态为非MUTANT,则当前状态为FULLY-GROWN,否则为MUTANT
3) 如果序列为BxxxA, 如果xxx的状态为非MUTANT,则当前状态为MUTAGENIC,否则为MUTANT
4) 其他序列为MUTANT
ps: 当细胞数为偶数,必然为MUTANT
*/
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
char st[4][20] = {"SIMPLE", "FULLY-GROWN", "MUTAGENIC", "MUTANT"};
char A[1000];
int dp(int x, int y) {
if(y-x == 1) {
return A[x]=='A' ? 0 : 3;
}
if(A[y-1]=='B' && A[y-2]=='A') return dp(x, y-2)==3 ? 3 : 1;
if(A[x]=='B' && A[y-1]=='A') return dp(x+1, y-1)==3 ? 3 : 2;
return 3;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif
int n, ans;
scanf("%d", &n);
for(int i=0; i<n; i++) {
scanf("%s", A);
int len = strlen(A);
if(!len%2) ans = 3;
else {
ans = dp(0, len);
}
printf("%s\n", st[ans]);
}
}
UVa 620 - Cellular Structure
最新推荐文章于 2021-06-20 19:35:04 发布
