UVa 620 Cellular Structure

Description

Download as PDF

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:

$\bullet$ simple stage 		 O = A $\bullet$ fully-grown stage 		 O = OAB $\bullet$ 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;
}



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值