博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu-2612Find a way(bfs 求两个人到同一家kfs所需时间最短)
阅读量:4048 次
发布时间:2019-05-25

本文共 2155 字,大约阅读时间需要 7 分钟。

Find a way

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 10758    Accepted Submission(s): 3538


Problem Description
Pass a year learning in Hangzhou, yifenfei arrival 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.
 

Input
The input contains multiple test cases.
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
 

Output
For each test case output the minimum total time that both yifenfei and Merceki to arrival one of KFC.You may sure there is always have a KFC that can let them meet.
 

Sample Input
4 4Y.#@.....#..@..M4 4Y.#@.....#..@#.M5 5Y..@..#....#...@..M.#...#
 

Sample Output
668866
 

Author
yifenfei
 

Source
 

Recommend
yifenfei   |   We have carefully selected several similar problems for you:            
#include
#include
#include
#include
#include
#define inf 0x6ffffffusing namespace std;int vis[250][250];char map[250][250];int dx[]={ 1,-1,0,0};int dy[]={ 0,0,1,-1};int s1,s2;int s3,s4;int flag[250][250];//用于记录步数int flag2[250][250];int n,m;typedef pair
p;void bfs(int sx,int sy,int a[250][250]){ queue

que; que.push(p(sx,sy)); vis[sx][sy]=1; while(!que.empty()) { p now=que.front(); que.pop(); int ex=now.first; int ey=now.second; for(int i=0;i<4;i++) { int x=ex+dx[i]; int y=ey+dy[i]; //cout<

<<" "<
<
=n||x<0||y>=m||y<0||vis[x][y]||map[x][y]=='#') continue; if(x
y&&x>=0&&y>=0&&map[x][y]!='#'&&!vis[x][y]) { vis[x][y]=1; a[x][y]=a[ex][ey]+1; } que.push(p(x,y)); } }}int main(){ while(~scanf("%d%d",&n,&m)) { for(int i=0;i

 

转载地址:http://fafci.baihongyu.com/

你可能感兴趣的文章
Ubuntu 13.10使用fcitx输入法
查看>>
pidgin-lwqq 安装
查看>>
mint/ubuntu安装搜狗输入法
查看>>
C++动态申请数组和参数传递问题
查看>>
opencv学习——在MFC中读取和显示图像
查看>>
C/C++中关于动态生成一维数组和二维数组的学习
查看>>
JVM最简生存指南
查看>>
Java的对象驻留
查看>>
JVM并发机制探讨—内存模型、内存可见性和指令重排序
查看>>
持续可用与CAP理论 – 一个系统开发者的观点
查看>>
nginx+tomcat+memcached (msm)实现 session同步复制
查看>>
c++字符数组和字符指针区别以及str***函数
查看>>
c++类的操作符重载注意事项
查看>>
c++模板与泛型编程
查看>>
WAV文件解析
查看>>
WPF中PATH使用AI导出SVG的方法
查看>>
WPF UI&控件免费开源库
查看>>
QT打开项目提示no valid settings file could be found
查看>>
Win10+VS+ESP32环境搭建
查看>>
Ubuntu+win10远程桌面
查看>>