题意:
一个细胞群有三种形态:
1. OA, simple
2. OAB, fully
3. BOA, mutagenic
else: mutant
要求一个细胞群里面只存在这三种形态的细胞,否则就变异啦。
解析:
按三种细胞形态一个一个递归。
详见代码。
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <map>
#define LL long long
using namespace std;
const int maxn = 1e6;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
const double pi = 4 * atan(1.0);
const double ee = exp(1.0);
char str[100];
int dfs(int lo, int hi)
{
if (lo == hi && str[lo] == 'A')
return 1;
else if (hi - lo >= 1 && str[hi] == 'A' && dfs(lo, hi - 1))
return 1;
else if (hi - lo >= 2 && str[hi] == 'B' && str[hi - 1] == 'A' && dfs(lo, hi - 2))
return 2;
else if (hi - lo >= 2 && str[hi] == 'A' && str[lo] == 'B' && dfs(lo + 1, hi - 1))
return 3;
return 0;
}
int main()
{
#ifdef LOCAL
freopen("in.txt", "r", stdin);
#endif // LOCAL
int ncase;
scanf("%d", &ncase);
while (ncase--)
{
scanf("%s", str);
int len = strlen(str);
int ans = dfs(0, len - 1);
if(ans == 1)
printf("SIMPLE\n");
else if(ans == 2)
printf("FULLY-GROWN\n");
else if(ans == 3)
printf("MUTAGENIC\n");
else
printf("MUTANT\n");
}
return 0;
}