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;
    }


    
    
  • 相关阅读:
    iOS开发UI篇—Quartz2D使用(截屏)
    iOS开发UI篇—Quartz2D使用(信纸条纹)
    iOS开发UI篇—Quartz2D使用(绘图路径)
    iOS开发UI篇—Quartz2D简单使用(三)
    戴文的Linux内核专题:04安全
    戴文的Linux内核专题:03驱动程序
    戴文的Linux内核专题:02源代码
    戴文的Linux内核专题:01介绍
    nginx+php+扩展件安装实践版
    git常用命令
  • 原文地址:https://www.cnblogs.com/pangblog/p/3299431.html
Copyright © 2011-2022 走看看