UVA 620 Cellular Structure 蜂窝结构
2015-08-18 11:16
405 查看
原题:
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:
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种的结构。
思路见代码下方:
思路:
我在UVATOOKIT上测试数据的时候看到标签上贴个DP,还以为自己的代码会超时,结果0秒过了。
就是用简单的搜索,找每次寻找当前结构是否符合三种基本生长结构即可。 另外,这题怎么dp呢?
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:
[code] 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种的结构。
思路见代码下方:
[code]#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呢?
相关文章推荐
- CF #312.div2 -Amr and Chemistry-暴力+位运算
- 从CPU核心架构看2016年移动设备趋势,A72到底能带来什么?
- C++零基础教程游戏开发入门
- 常用注释总结
- Maven实践一:HelloWord项目构建部署
- 给ubuntu中的软件设置desktop快捷方式(以android studio为例)
- uefi 里面如何抓到一个变量
- 妇仇者联盟--寡姐时代
- Go语言net/http 解读.
- Cocos2d-x学习笔记(十三)—— 数据解析(json/xml)
- java接口和抽象类
- hdoj.2256 Problem of Precision【矩阵快速幂】 2015/08/18
- hdoj 3342 Legal or Not 【拓朴排序】
- vijos - P1447开关灯泡 (大数模板 + 找规律 + 完全数 + python)
- 19.6.1 Partitioning Keys, Primary Keys, and Unique Keys 分区键,主键,和唯一健
- Hdu oj 2066 一个人的旅行
- #程序猿之路需要自己来铺垫#
- 第六章、输入输出系统
- JQuery实现数字滚动增加的效果
- Component Object Model