思路:直接用优先队列优化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. 第35题:LeetCode138. Copy List with Random Pointer

    题目 给定一个链表,每个节点包含一个额外增加的随机指针,该指针可以指向链表中的任何节点或空节点. 要求返回这个链表的深度拷贝. 考点 思路 代码 /** * Definition for singly ...

  2. 【经典问题】bzoj2957: 楼房重建

    经典问题:动态维护上升子序列长度 进阶问题:[经典问题]#176. 栈 Description 小A的楼房外有一大片施工工地,工地上有N栋待建的楼房.每天,这片工地上的房子拆了又建.建了又拆.他经常无 ...

  3. 【例题收藏】◇例题·I◇ Snuke's Subway Trip

    ◇例题·I◇ Snuke's Subway Trip 题目来源:Atcoder Regular 061 E题(beta版) +传送门+ 一.解析 (1)最短路实现 由于在同一家公司的铁路上移动是不花费 ...

  4. Maven - 依赖范围<scope></scope>

    6种:

  5. mysql 1055 的错误

    1.Err1055,出现这个问题往往是在执行sql语句时候,在最后一行会出现这个问题. [Err] 1055 - Expression #1 of ORDER BY clause is not in ...

  6. PHP递归操作

    对于php的递归操作解释说明,递归基本上是学习每种语言都要会的最基本的操作.来吧,下面是我闲的时候随便写的一个对数组进行遍历操作的一个递归函数. 原理很简单,递归就是在一个函数里面调用自身的一种机制. ...

  7. POJ 3484 二分

    Showstopper Description Data-mining huge data sets can be a painful and long lasting process if we a ...

  8. 008---Django的模版层

    python的模板:HTML代码+模板语法 <!--模版语法之变量--> <h1>Index </h1> <p>{{ name }}</p> ...

  9. 1、spring boot入门

    1.Spring Boot 简介 简化Spring应用开发的一个框架: 整个Spring技术栈的一个大整合: J2EE开发的一站式解决方案: 2.微服务 2014,martin fowler 微服务: ...

  10. android stadio 打开别人的工程 一直在编译中

    这是因为,他工程的gradle 配置,在你本地找不到,所以,会去网上下.然后解压,使用.这是一个很漫长的过程. *那么怎么做呢 修改项目工程的gradle/wrapper/gradle-wrapper ...