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目标必须一致. 于 ...
随机推荐
- 通过谷歌浏览器,找到页面某个事件属于哪个js文件
在进行web开发中,有时候需要找到某个事件是属于哪个js文件,以便对文件进行修改,进行代码开发 1.打开谷歌浏览器, 打开事件所在页面, 鼠标右键, 点击"检查"项; 2.选中El ...
- 面对对象编程(OOP, Object Oriented Programming)及其三个基本特性
一千个读者,一千个哈姆雷特.对于面对对象编程,书上都会告诉我们它有三个基本特性,封装,继承,多态,但谈起对这三点的见解,又是仁者见仁智者见智,感觉还是得多去编程中体验把 . 面向对象编程(OOP, O ...
- 完整的REM布局的工作流程与规范
rem从去年的手淘双11开始火起来之后一直就想去使用,但是苦于学习途径有限,工作任务也比较繁忙导致一度延后. 那么现在对相关知识的学习与初步的项目实践之后,在这里记录一下使用rem解决各屏幕适配问题. ...
- eclipse上搭建Spring环境
搭建环境之前要下载Spring Tool Suite和Spring framework 1.Spring IDE 下载(也叫Spring Tool Suite 简称 STS),进官网,直接给链接htt ...
- 在vue项目中安装使用Mint-UI
一.Mint UI 是 由饿了么前端团队推出的 一个基于 Vue.js 的移动端组件库,具有以下特性: 使用文档: http://mint-ui.github.io/#!/zh-cn Mi ...
- JavaWeb 基础面试
1. 启动项目时如何实现不在链接里输入项目名就能启动? 修改Tomcat配置文件 server.xml.找到自己的项目配置 : <Context docBase="oneProjec ...
- POJ 1018
#include<iostream> #define MAXN 105 #define inf 10000000 #include<vector> #include<io ...
- 对称(DES/AES)与非对称(RSA/SSL/数字证书)加密介绍及实际应用
本文不对具体的算法做深入研究,只是讲解各种安全算法的原理和使用场景. 一.数据校验算法 数据校验,是为保护数据的完整性,用一种指定的算法对原始数据计算出的一个校验值.当接收方用同样的算法再算一次校验值 ...
- SocketIo+SpringMvc实现文件的上传下载
SocketIo+SpringMvc实现文件的上传下载 socketIo不仅可以用来做聊天工具,也可以实现局域网(当然你如果有外网也可用外网)内实现文件的上传和下载,下面是代码的效果演示: GIT地址 ...
- C/C++ -- Gui编程 -- Qt库的使用 -- 使用自定义类
1.新建空Qt工程 2.新建C++类HelloQt 3.新建ui文件,添加部件,重命名主窗体(对话框)类名HelloQt,构建生成ui头文件 4.修改头文件helloqt.h #ifndef HELL ...