UVA 620 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
题目大意:
(真题看了n久才看懂),告诉你有一个链式结构,这个结构有4种生长方式,一种是A,就是只有一个A。另外一种是OAB,就是在原来的链式上加上AB,或者只有AB。第三种是在BOA,在原来的链的后面加个B,在前面加个A。第四种就是不满足上面3种的结构。
思路见代码下方:

#include<iostream>
#include<algorithm>
#include<map>
#include<string>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<vector>
#include<cmath>
#include<stack>
using namespace std;
string str;
bool dfs(int s,int e)
{
    if(e==s&&str[s]=='A')
    return true;
    if(e-s==1&&str[s]=='A'&&str[e]=='B')
    return true;
    if(str[e]=='B'&&str[e-1]=='A')
    {
        if(dfs(s,e-2))
        return true;
    }
    if(str[s]=='B'&&str[e]=='A')
    {
        if(dfs(s+1,e-1))
        return true;
    }
    return false;
}
int main()
{
    ios::sync_with_stdio(false);
    int n,flag;
    cin>>n;
    while(n--)
    {
        cin>>str;
        flag=1;
        if(str=="A")
        {
            cout<<"SIMPLE"<<endl;
            flag=0;
        }
        else
        {
            if(str[str.size()-1]=='B'&&str[str.size()-2]=='A')
            {
                if(dfs(0,str.size()-1))
                {
                    cout<<"FULLY-GROWN"<<endl;
                    flag=0;
                }
            }
            else
            {
                if(str[0]=='B'&&str[str.size()-1]=='A')
                {
                    if(dfs(0,str.size()-1))
                    {
                        cout<<"MUTAGENIC"<<endl;
                        flag=0;
                    }
                }
            }
        }
        if(flag)
        cout<<"MUTANT"<<endl;
    }
    return 0;
}




思路:
我在UVATOOKIT上测试数据的时候看到标签上贴个DP,还以为自己的代码会超时,结果0秒过了。
就是用简单的搜索,找每次寻找当前结构是否符合三种基本生长结构即可。 另外,这题怎么dp呢?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值