hust 1605 bfs
思路:直接用优先队列优化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的更多相关文章
- hust 1605 - Gene recombination(bfs+字典树)
1605 - Gene recombination Time Limit: 2s Memory Limit: 64MB Submissions: 264 Solved: 46 DESCRIPTION ...
- HUST 1605 Gene recombination
简单广搜.4进制对应的10进制数来表示这些状态,总共只有(4^12)种状态. #include<cstdio> #include<cstring> #include<cm ...
- HUST 1605 Gene recombination(广搜,位运算)
题目描述 As a gene engineer of a gene engineering project, Enigma encountered a puzzle about gene recomb ...
- BFS 巡逻机器人
巡逻机器人 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=83498#problem/F 题目大意: 机器人在一个矩形区域巡逻, ...
- BFS 骑士的移动
骑士的移动 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=83498#problem/E 题目: Description A f ...
- AOJ 0121: Seven Puzzle (BFS DP STL 逆向推理)(转载)
转载自: http://m.blog.csdn.net/blog/Enjoying_Science/42008801 题目链接:http://acm.hust.edu.cn/vjudge/probl ...
- loj 1185(bfs)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=26898 思路:我们可以给定有直接边相连的两点的距离为1,那么就是求 ...
- loj 1165(bfs+康托展开)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=26879 思路:题目意思很简单,就是通过一些位置的交换,最后变成有序 ...
- loj 1055(bfs)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=26772 思路:注意判重就行,开个6维数组记录3个robots的位置 ...
随机推荐
- 理解css中的position属性
理解css中的position 两种类型的定位 static类型:只有一个值position: static.position默认值 relative类型:包括三个值,这三个值会相互影响,允许你以特定 ...
- 使用工具Android Studio实现一个简单的Android版的新闻APP
目的: 这是我学完Android课程后所写的一个小的.简单版的新闻APP 技术概要: 用到了SQLite数据库,用它来存储每篇新闻下的评论 新闻的来源是新浪新闻,我通过使用Fiddler来对新浪新闻A ...
- 泉五培训Day3
T1 家庭作业 题目 [问题描述] 小P为了能高效完成作业,规定每项作业花一个单位时间. 他的学习日从0时刻开始,有100000个单位时间.在任一时刻,他都可以选择编号1~N的N项作业中的任意一项作业 ...
- 前端之HTML和CSS
html概述及html文档基本结构 html概述 HTML是 HyperText Mark-up Language 的首字母简写,意思是超文本标记语言,超文本指的是超链接,标记指的是标签,是一种用来制 ...
- Redis 数据类型List链表
list类型是一个双向链表. 上进上出:栈 例1 lpush newlogin tom lpush newlogin jim lpush newlogin php lpush newlogin th ...
- 【PHP基础】序列化serialize()与反序列化unserialize()
序列化serialize()与反序列化unserialize(): 序列化serialize():就是将一个变量所代表的 “内存数据”转换为“字符串”的形式,并持久保存在硬盘(写入文件中保存)上的一种 ...
- Python学习之函数参数
上一节,我们学习了Python中是如何定义和调用函数且如何得到返回值的.在调用函数时,有的函数需要参数来启动函数,有的则无需参数.这一节我们来介绍Python中有哪些参数类型. 位置参数 在调用函数时 ...
- Partitioning by Palindromes UVA - 11584 简单dp
题目:题目链接 思路:预处理出l到r为回文串的子串,然后如果j到i为回文串,dp[i] = min(dp[i], dp[j] + 1) AC代码: #include <iostream> ...
- Poweroj:2425-跳台阶(经典递推)
题目链接:https://www.oj.swust.edu.cn/problem/show/2425 跳台阶 Edit Manage Data Rejudge Time Limit: 1000 MS ...
- 18,Shell编程实战
为什么要学习Shell编程 Shell脚本语言是实现Linux/Unix系统管理及自动化运维所必须的重要工具,Linux系统的底层以及基础应用软件的核心大都涉及Shell脚本的内容. 一个合格的L ...