HUST 1605 Gene recombination
简单广搜。4进制对应的10进制数来表示这些状态,总共只有(4^12)种状态。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<algorithm>
using namespace std; const int maxn = ;
bool m[];
struct P
{
int state;
int tot;
};
queue<P>Q;
char s1[maxn], s2[maxn];
int tmp1[maxn], r1, tmp2[maxn], r2;
int A, B;
int n;
int b[maxn]; int f(char sign)
{
if (sign == 'A') return ;
if (sign == 'T') return ;
if (sign == 'G') return ;
if (sign == 'C') return ;
} void init()
{
while (!Q.empty()) Q.pop();
memset(m, , sizeof m); A = B = ;
for (int i = ; s1[i]; i++) A = A + f(s1[i])*b[i];
for (int i = ; s2[i]; i++) B = B + f(s2[i])*b[i];
} void BFS()
{
P now; now.state = A; now.tot = ; m[A] = ; Q.push(now);
while (!Q.empty())
{
P head = Q.front(); Q.pop();
if (head.state == B)
{
printf("%d\n", head.tot);
break;
} memset(tmp1, , sizeof tmp1);
memset(tmp2, , sizeof tmp2); r2 = r1 = ; int w = head.state;
while (w) tmp2[r2++] = tmp1[r1++] = w % , w = w / ; swap(tmp1[], tmp1[]);
int new_state = ;
for (int i = ; i < n; i++) new_state = new_state + tmp1[i] * b[i]; if (m[new_state] == )
{
m[new_state] = ;
P d; d.state = new_state; d.tot = head.tot + ;
Q.push(d);
} new_state = ;
tmp2[n] = tmp2[];
for (int i = ; i <= n; i++) new_state = new_state + tmp2[i] * b[i - ]; if (m[new_state] == )
{
m[new_state] = ;
P d; d.state = new_state; d.tot = head.tot + ;
Q.push(d);
}
}
} int main()
{
b[] = ; for (int i = ; i <= ; i++) b[i] = * b[i - ]; while (~scanf("%d", &n))
{
scanf("%s%s", s1, s2);
init();
BFS();
}
return ;
}
HUST 1605 Gene recombination的更多相关文章
- hust 1605 - Gene recombination(bfs+字典树)
1605 - Gene recombination Time Limit: 2s Memory Limit: 64MB Submissions: 264 Solved: 46 DESCRIPTION ...
- HUST 1605 Gene recombination(广搜,位运算)
题目描述 As a gene engineer of a gene engineering project, Enigma encountered a puzzle about gene recomb ...
- hust 1605 bfs
思路:直接用优先队列优化bfs. #include<map> #include<queue> #include<vector> #include<cmath& ...
- HUST 1017 - Exact cover (Dancing Links 模板题)
1017 - Exact cover 时间限制:15秒 内存限制:128兆 自定评测 5584 次提交 2975 次通过 题目描述 There is an N*M matrix with only 0 ...
- KEGG and Gene Ontology Mapping in Bioinformatic Method
使用KOBAS进行KEGG pathway和Gene Ontology分析 Article from Blog of Alfred-Feng http://blog.sina.com.cn/u/170 ...
- 合并基因表达水平(merge gene expression levels, FPKM)
使用tophat和cufflinks计算RNA-seq数据的表达水平时,当一个基因在一个样本中有多个表达水平时需要合并它们的表达水平. This code is a solution to colla ...
- augustus, gene prediction, trainning
做基因组注释 先用augustus训练,然后再用maker做基因注释 augustus提供一些训练好的,如果有和你的物种非常接近的,直接用提供的,没有的话再自己训练. 网址: http://bioin ...
- ubuntu 16.04 source (HUST and 163)
#HUST deb http://mirrors.hust.edu.cn/ubuntu/ xenial main restricted universe multiverse deb http://m ...
- Dancing Link --- 模板题 HUST 1017 - Exact cover
1017 - Exact cover Problem's Link: http://acm.hust.edu.cn/problem/show/1017 Mean: 给定一个由0-1组成的矩阵,是否 ...
随机推荐
- Android中Canvas绘图基础详解(附源码下载) (转)
Android中Canvas绘图基础详解(附源码下载) 原文链接 http://blog.csdn.net/iispring/article/details/49770651 AndroidCa ...
- AI 人工智能 探索 (四)
在写之前,先对昨天寻路插件再做一些补充,因为该插件不是很完善,所以当我发现有不能满足需求的时候,就会试图更改源代码,或增加接口来符合我的需求. 昨天补充了一条是 自身转向代码,今天补充另外一条,是及时 ...
- sql 按时间二段排序
业务需用为数据按倒序排序,当天数据排在以往日期前面,但当天数据需按小时进行升序排列 select *from( select vcTitle,dtBeginDate,case when dtBegin ...
- Tomcat 虚拟目录映射
最近老是被一个旧Ant工程所困扰,代码版本都改好了测试也通过了,就是打不了war包,一看build.xml 我的天 各种逆天啊....头大.于是乎想起了最基础的tomcat虚拟目录虽是一个很基础的点, ...
- 2--OC -- 类的创建与实例化
2.OC -- 类的创建与实例化 一.OC类的简述 1.OC类分为2个文件:.h文件用于类的声明,.m文件用于实现.h的函数: 2.类是声明使用关键字:@interface.@end : 3.类是 ...
- 学习笔记——建造者模式Builder
构造者模式.外部场景如果需要一个汽车类,它不需要关心如何构造,它只需要告诉Director需要什么,就可以从Director获得. 如:CDirector(IBuilder* aBuilder); 场 ...
- android sql Cursor
Cursor 是每行的集合. 使用 moveToFirst() 定位第一行. 你必须知道每一列的名称.你必须知道每一列的数据类型.Cursor 是一个随机的数据源. 所有的数据都是通过下标取得. Cu ...
- Linux学习 -- 日志管理
日志服务 rsyslogd CentOS6 取代了原来的syslog rsyslogd 默认启动.自启动 常用命令:lastb.lastlog.last.w.who.users. 系统默认日志 和 ...
- openstack镜像如何在vmware 环境中运行
1.云镜像文件下载地址: http://sahara-files.mirantis.com/sahara-juno-spark-1.0.0-ubuntu-14.04.qcow2(安装有sahara-s ...
- 如何用好 Google 搜索引擎?
1.双引号 把搜索词放在双引号中,代表完全匹配搜索,也就是说搜索结果返回的页面包含双引号中出现的所有的词,连顺序也必须完全匹配.bd和Google 都支持这个指令.例如搜索: “seo方法图片” 2. ...