博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Find a way HDU - 2612
阅读量:4686 次
发布时间:2019-06-09

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

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. 

InputThe 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 
OutputFor 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
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;const int INF=204;const int M=0x1f1f1f1f;int n,m,z;char cnt[INF][INF];int dir[][2]={ { 1,0},{ 0,-1},{-1,0},{ 0,1}};int dis[INF][INF][2];int vis[INF][INF];struct Node{ int x,y,step; Node(int x,int y,int z):x(x),y(y),step(z){} Node(){}};void bfs(int x,int y){ memset(vis,0,sizeof(vis)); vis[x][y]=1; queue
q; q.push(Node(x,y,0)); while(!q.empty()){ Node u=q.front(); q.pop(); for(int i=0;i<4;i++){ int tx=u.x+dir[i][0]; int ty=u.y+dir[i][1]; if(!vis[tx][ty]&&tx>=1&&tx<=n&&ty>=1&&ty<=m&&cnt[tx][ty]!='#'){ vis[tx][ty]=1; dis[tx][ty][z]=u.step+1; q.push(Node(tx,ty,u.step+1)); } } }}int main(){ while(cin>>n>>m){ for(int i=0;i<2;i++){ for(int j=1;j<=n;j++){ for(int k=1;k<=m;k++) dis[j][k][i]=M; } } for(int i=1;i<=n;i++) scanf("%s",cnt[i]+1); for(int i=1;i<=n;++i) for(int j=1;j<=m;j++){ if(cnt[i][j]=='Y'){ z=1; bfs(i,j); } if(cnt[i][j]=='M'){ z=0; bfs(i,j); } } int ans=M; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ if(cnt[i][j]=='@'){ //去同一家KFC的距离之和 ans=min(ans,dis[i][j][0]+dis[i][j][1]); } } } cout<
<

 

转载于:https://www.cnblogs.com/CuteAbacus/p/9492221.html

你可能感兴趣的文章
什么是html,什么是php
查看>>
(并行编程)SpinLock
查看>>
浅谈 Java XML 底层解析方式
查看>>
ADO.NET介绍
查看>>
贪吃蛇easyx版本
查看>>
百度地图 JS API开发Demo01
查看>>
采用javascript实现WebGIS页面元素动态布局
查看>>
约瑟夫环问题
查看>>
Real-Time C++: Efficient Object-Oriented and Template Microcontroller Programming.pdf
查看>>
WPF 获取指定文件的Icon
查看>>
mysql实践(四)
查看>>
在linux服务器上配置anaconda和Tensorflow,并运行
查看>>
[POJ2823][洛谷P1886]滑动窗口 Sliding Window
查看>>
Flex 4.x 下载进度不出现问题解决办法
查看>>
Vue之自定义组件的v-model
查看>>
Vue项目碰到"‘webpack-dev-server’不是内部或外部命令,也不是可运行的程序或批处理文件"报错...
查看>>
解决Xcode在ipad/iphone 9.2 系统真机测试时出现could not find developer disk image问题
查看>>
基于asp.net的ajax分页
查看>>
分布式事务,两阶段提交协议,三阶段提交协议
查看>>
php/js获取客户端mac地址的实现代码
查看>>