思路:直接用优先队列优化bfs。

#include<map>
#include<queue>
#include<vector>
#include<cmath>
#include<string>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define Maxn 100010
#define inf 1<<30
using namespace std;
map<int,int> g;
int ans,n,ha[],Exp[];
char s[];
int tar;
struct QT{
int val,st;
int operator <(const QT &temp) const{
return st>temp.st;
}
};
priority_queue<QT> q;
int bfs(int temp)
{
int i,j,str;
while(!q.empty()) q.pop();
QT tt,p;
tt.val=temp,tt.st=;
q.push(tt);
while(!q.empty()){
p=q.top();
q.pop();
str=p.val;
if(str==tar) return p.st;
int a,b;
a=str/Exp[n-];
b=str%Exp[n-]/Exp[n-];
temp=b*Exp[n-]+a*Exp[n-]+str%Exp[n-];
if(!g[temp]){
tt.val=temp,tt.st=p.st+;
q.push(tt);
g[temp]=;
}
temp=str%Exp[n-]*+str/Exp[n-];
if(!g[temp]){
tt.val=temp,tt.st=p.st+;
q.push(tt);
g[temp]=;
}
}
}
int main()
{
char str[];
int i,j;
ha['A']=;
ha['G']=;
ha['C']=;
ha['T']=;
Exp[]=;
for(int i=;i<;i++)
Exp[i]=Exp[i-]*;
while(scanf("%d",&n)!=EOF){
ans=inf;
g.clear();
scanf("%s%s",str,s);
tar=;
int temp=;
for(i=;i<n;i++){
tar=tar*+ha[s[i]];
temp=temp*+ha[str[i]];
}
printf("%d\n",bfs(temp));
}
return ;
}

hust 1605 bfs的更多相关文章

  1. hust 1605 - Gene recombination(bfs+字典树)

    1605 - Gene recombination Time Limit: 2s Memory Limit: 64MB Submissions: 264 Solved: 46 DESCRIPTION ...

  2. HUST 1605 Gene recombination

    简单广搜.4进制对应的10进制数来表示这些状态,总共只有(4^12)种状态. #include<cstdio> #include<cstring> #include<cm ...

  3. HUST 1605 Gene recombination(广搜,位运算)

    题目描述 As a gene engineer of a gene engineering project, Enigma encountered a puzzle about gene recomb ...

  4. BFS 巡逻机器人

    巡逻机器人 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=83498#problem/F 题目大意: 机器人在一个矩形区域巡逻, ...

  5. BFS 骑士的移动

    骑士的移动 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=83498#problem/E 题目: Description A f ...

  6. AOJ 0121: Seven Puzzle (BFS DP STL 逆向推理)(转载)

    转载自:  http://m.blog.csdn.net/blog/Enjoying_Science/42008801 题目链接:http://acm.hust.edu.cn/vjudge/probl ...

  7. loj 1185(bfs)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=26898 思路:我们可以给定有直接边相连的两点的距离为1,那么就是求 ...

  8. loj 1165(bfs+康托展开)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=26879 思路:题目意思很简单,就是通过一些位置的交换,最后变成有序 ...

  9. loj 1055(bfs)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=26772 思路:注意判重就行,开个6维数组记录3个robots的位置 ...

随机推荐

  1. 深入浅出:了解JavaScript中的call,apply,bind的差别

     在 javascript之 this 关键字详解文章中,谈及了如下内容,做一个简单的回顾:         1.this对象的涵义就是指向当前对象中的属性和方法.       2.this指向的可变 ...

  2. int ,long long 范围

    类型名称 字节数 取值范围signed char 1 -128-+127short int 2 -32768-+32767int 4 -2147483648-+2147483647(10位数 2^31 ...

  3. Spring Cloud 入门Eureka -Consumer服务消费(声明式Feign)(三)

    Spring Cloud Feign是一套基于Netflix Feign实现的声明式服务调用客户端.它使得编写Web服务客户端变得更加简单.我们只需要通过创建接口并用注解来配置它既可完成对Web服务接 ...

  4. JavaScript - 库 jQuery

    测试 JavaScript 框架库 - jQuery 引用JQuery 如需测试JavaScript库,您需要在网页中引用它. 为了引用某个库,请使用<script>标签,其src属性设置 ...

  5. scrapy--matplotlib

    昨天晚上看了一些关于保存文件的相关资料,早早的睡了,白天根据网上查找的资料,自己再捡起来.弄了一上午就爬取出来了,开心!!!好吧,让我们开始 老规矩,先上图.大家也赶快行动起来 分类文件: 文件内co ...

  6. 一行代码搞定checkbox全选和全不选

    <!DOCTYPE html><html> <head> <meta charset="utf-8" /> <title> ...

  7. 右键git-bash不能使用

    主要:右键git-bash不能使用 右键git-bash不能使用 今日想用git传写代码到仓库,突然发现几天没有却出问题了,右键出现了错误,虽然很快解决了,但还是可以记录下 情形: 右键存在但不能使用 ...

  8. U盘装机记录

    U盘装机记录 1. 将U盘制作为启动盘(安装PE文件到U盘). (1)准备材料 8G以上U盘一个 一个可信的启动盘制作工具(这里是用的老毛桃) (2)将U盘插入电脑,单击老毛桃客户端(出现如下图所示的 ...

  9. IAR 编译时找不到头文件的解决方法

    Fatal Error[Pe1696]: cannot open source file "x.h" 那是因为头文件路径没有找对 到报错的.c源文件 选中右键 选择options ...

  10. 第二章习题 C++

    1.编写一个程序,显示您的姓名和地址. #include<iostream> using namespace std; int main() { ]; cout << &quo ...