zoukankan      html  css  js  c++  java
  • UVA 620 Cellular Structure (dp)

     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:

     

    
    $ullet$
    simple stage 		 O = A  
    $ullet$
    fully-grown stage 		 O = OAB 
    $ullet$
    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
    

    题意:如题,一个细胞有三种生长方式。求出当前细胞的上一个生长方式。
    思路:由当前细胞一直往之前的状态找即可。直到找到结束或者不能再往下找了位置。
    代码:

     

    #include <stdio.h>
    #include <string.h>
    
    int t, len;
    char ans[4][20] = {"SIMPLE", "FULLY-GROWN", "MUTANT", "MUTAGENIC"};
    char str[1005];
    
    int dp(int start, int end) {
    	if (end - start == 1 && str[start] == 'A') {
    		return 0;
    	}
    	else if (str[start] == 'B' && str[end - 1] == 'A') {
    		if (dp(start + 1, end - 1) != 2) {
    			return 3;
    		}
    	}
    	else if (str[end - 1] == 'B' && str[end - 2] == 'A') {
    		if (dp(start, end - 2) != 2) {
    			return 1;
    		}
    	}
    	return 2;
    }
    int main() {
    	scanf("%d%*c", &t);
    	while (t --) {
    		gets(str);
    		len = strlen(str);
    		printf("%s
    ", ans[dp(0, len)]);
    	}
    	return 0;
    }


    
    
  • 相关阅读:
    创建共享内存函数CreateFileMapping()详解
    窗口类、窗口类对象与窗口
    ubuntu中文版切换为英文后字体变化问题解决
    安装ubuntu12.04LTS卡住以及花屏问题
    时钟周期、振荡周期、机器周期、CPU周期、状态周期、指令周期、总线周期、任务周期
    波特率
    myod
    mycp
    20165226 2017-2018-2《Java程序设计》课程总结
    2017-2018-2 20165226 实验五《网络编程与安全》实验报告
  • 原文地址:https://www.cnblogs.com/pangblog/p/3299431.html
Copyright © 2011-2022 走看看