hdu 2612
Find a way
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3451 Accepted Submission(s):
1128
hometown Ningbo at finally. Leave Ningbo one year, yifenfei have many people to
meet. Especially a good friend Merceki.
Yifenfei’s home is at the
countryside, but Merceki’s home is in the center of city. So yifenfei made
arrangements with Merceki to meet at a KFC. There are many KFC in Ningbo, they
want to choose one that let the total time to it be most smallest.
Now give
you a Ningbo map, Both yifenfei and Merceki can move up, down ,left, right to
the adjacent road by cost 11 minutes.
Each test
case include, first two integers n, m. (2<=n,m<=200).
Next n lines,
each line included m character.
‘Y’ express yifenfei initial position.
‘M’
express Merceki initial position.
‘#’ forbid road;
‘.’ Road.
‘@’
KCF
both yifenfei and Merceki to arrival one of KFC.You may sure there is always
have a KFC that can let them meet.
4 4
Y.#@
....
.#..
@..M
4 4
Y.#@
....
.#..
@#.M
5 5
Y..@.
.#...
.#...
@..M.
#...#
6 5
Y.@#.
.#.#.
.#.#.
.#.#.
.#.#.
##M..
77
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<queue>
using namespace std; int n,m;
int yx,yy,mx,my;
int to[][]={{,},{,},{-,},{,-}};
char a[][];
int time[][][];
bool hash[][][];
bool flag;
struct node
{
int x,y;
int time;
};
queue<node>Q[]; int Min(int x,int y)
{
return x>y? y:x;
}
bool pd(node &t)
{
if(t.x>=&&t.x<=n && t.y>=&&t.y<=m && a[t.x][t.y]!='#')return false;
return true;
}
int bfs(int x)
{
int i,hxl=;
node t,cur; while(!Q[x].empty())
{
cur=Q[x].front();
Q[x].pop();
for(i=;i<;i++)
{
t=cur;
t.x=t.x+to[i][];
t.y=t.y+to[i][];
t.time++;
if(pd(t))continue;
if(hash[x][t.x][t.y])continue;
hash[x][t.x][t.y]=true;
time[x][t.x][t.y]=t.time;
if(x== && a[t.x][t.y]=='@')
{
hxl=Min(hxl,time[x^][t.x][t.y]+time[x][t.x][t.y]);
}
Q[x].push(t);
}
}
return hxl;
}
void dbfs()
{
int ans=;
node t;
t.x=yx;
t.y=yy;
t.time=;
Q[].push(t);
hash[][yx][yy]=true; t.x=mx;
t.y=my;
t.time=;
Q[].push(t);
hash[][mx][my]=true; bfs();
ans = bfs();
printf("%d\n",ans*);
}
int main()
{
int i,j;
while(scanf("%d%d",&n,&m)>)
{
for(i=;i<=n;i++)
scanf("%s",a[i]+);
memset(hash,false,sizeof(hash));
memset(time,,sizeof(time));
for(i=;i<=n;i++)
for(j=;j<=m;j++){
if(a[i][j]=='Y'){
yx=i;
yy=j;
}
else if(a[i][j]=='M'){
mx=i;
my=j;
}
}
while(!Q[].empty()){
Q[].pop();
}
while(!Q[].empty()){
Q[].pop();
}
flag=false;
dbfs();
}
return ;
}
hdu 2612的更多相关文章
- HDU 2612 Find a way(找条路)
HDU 2612 Find a way(找条路) 00 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem ...
- HDU.2612 Find a way (BFS)
HDU.2612 Find a way (BFS) 题意分析 圣诞节要到了,坤神和瑞瑞这对基佬想一起去召唤师大峡谷开开车.百度地图一下,发现周围的召唤师大峡谷还不少,这对基佬纠结着,该去哪一个...坤 ...
- BFS(最短路) HDU 2612 Find a way
题目传送门 /* BFS:和UVA_11624差不多,本题就是分别求两个点到KFC的最短路,然后相加求最小值 */ /***************************************** ...
- HDU 2612 Find a way(双向bfs)
题目代号:HDU 2612 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2612 Find a way Time Limit: 3000/1000 M ...
- hdu 2612 Find a way
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2612 Find a way Description Pass a year learning in H ...
- HDU 2612 - Find a way - [BFS]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2612 Problem DescriptionPass a year learning in Hangz ...
- HDU 2612 Find a way bfs 难度:1
http://acm.hdu.edu.cn/showproblem.php?pid=2612 bfs两次就可将两个人到达所有kfc的时间求出,取两人时间之和最短的即可,这个有点不符合实情,题目应该出两 ...
- (广搜) Find a way -- hdu -- 2612
链接: http://acm.hdu.edu.cn/showproblem.php?pid=2612 Find a way Time Limit: 3000/1000 MS (Java/Others) ...
- HDU - 2612 Find a way 【BFS】
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=2612 题意 有两个人 要去一个城市中的KFC 一个城市中有多个KFC 求两个人到哪一个KFC的总时间最 ...
- HDU 2612 (BFS搜索+多终点)
题目链接: http://poj.org/problem?id=1947 题目大意:两人选择图中一个kfc约会.问两人到达时间之和的最小值. 解题思路: 对于一个KFC,两人的BFS目标必须一致. 于 ...
随机推荐
- java入门——面向对象
简介 对象具有自己的状态和行为: 描述一个对象具有什么状态和行为的过程叫做建模,不同的意图下我们对同一个事物的描述会产生不同的模型. 类 类描述一类对象的状态和行为的模板.可以把类想象成一个汽车设计图 ...
- 关于popup
p1.html:点击添加按钮,开启窗口,打开p2.html,填写数据后返回p3.html,p3.html将数据回传到p1.html,且关闭自己 p1.html: <!DOCTYPE html ...
- 【DC010沙龙年度合集】顶尖Hacking技术盛宴(文末福利)
岁末盘点,让我们一起回顾2017年DEFCON GROUP 010带来的那些最前端的Hacker技术,体验原汁原味的mini DEFCON黑客大会,满满的干货帮你开启Hacker技术大门 &g ...
- easyUI取消选中的所有行
在datagrid选择选中行进行展示后,再返回这个datagrid重新加载数据, 原来选中的数据还是保持选中状态.执行以下的方法还是如此,如图. $("#Table").datag ...
- Kafka数据可靠性与一致性解析
Partition Recovery机制 每个Partition会在磁盘记录一个RecoveryPoint, 记录已经flush到磁盘的最大offset.broker fail 重启时,会进行load ...
- Flask从入门到精通之使用Flask-Migrate实现数据库迁移
在开发程序的过程中,你会发现有时需要修改数据库模型,而且修改之后还需要更新数据库.仅当数据库表不存在时,Flask-SQLAlchemy 才会根据模型进行创建.因此,更新表的唯一方式就是先删除旧表,不 ...
- pg_stat_statements跳过的坑
pg_stat_statements跳过的坑 原本以为只是一个简单的插件扩展安装,三下五除二就能搞定,结果搞了很久也没找到问题所在.首先pg_stat_statements已经安装成功,且已经能够使用 ...
- centos7 防火墙与端口设置、linux端口范围
防火墙 启动防火墙: systemctl start firewalld 查看防火墙状态: systemctl status firewalld 关闭防火墙: systemctl stop firew ...
- (转)MySQL备份原理详解
MySQL备份原理详解 原文:http://www.cnblogs.com/cchust/p/5452557.html 备份是数据安全的最后一道防线,对于任何数据丢失的场景,备份虽然不一定能恢复百分之 ...
- MongoDB运行状态、性能监控,分析
转载自这位仁兄:地址 mongostat详解 mongostat是mongdb自带的状态检测工具,在命令行下使用.它会间隔固定时间获取mongodb的当前运行状态,并输出.如果你发现数据库突然变慢或者 ...