Find a way

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

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 4
Y.#@
....
.#..
@..M
4 4
Y.#@
....
.#..
@#.M
5 5
Y..@.
.#...
.#...
@..M.
#...#
 
Sample Output
66
88
66
简单的搜索,bfs,以Y和M为中心搜索
代码:

 #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<deque>
using namespace std;
const int maxn=;
typedef struct Map
{
char ss;
int x,y;
int value;
}gmap;
unsigned int dir[][]={{,},{-,},{,},{,-}}; /*·½Ïò*/
gmap bb[maxn][maxn];
int ans[maxn][maxn];
int n,m;
void bfs1(gmap a[][],int x,int y)
{
deque<gmap>q;
gmap temp;
q.push_back(a[x][y]);
while(!q.empty())
{
temp=q.front();
q.pop_front();
for(int i=;i</*&&temp.ss!='@'*/;i++)
{ if((temp.x+dir[i][])<||(temp.x+dir[i][])>=n||(temp.y+dir[i][])<||(temp.y+dir[i][])>=m) continue;
if(a[temp.x+dir[i][]][temp.y+dir[i][]].ss=='.'||a[temp.x+dir[i][]][temp.y+dir[i][]].ss=='@')
{
a[temp.x+dir[i][]][temp.y+dir[i][]].value+=temp.value+;
q.push_back(a[temp.x+dir[i][]][temp.y+dir[i][]]);
if(a[temp.x+dir[i][]][temp.y+dir[i][]].ss=='@')
{
a[temp.x+dir[i][]][temp.y+dir[i][]].ss='d';
ans[temp.x+dir[i][]][temp.y+dir[i][]]+=a[temp.x+dir[i][]][temp.y+dir[i][]].value;
}
else
a[temp.x+dir[i][]][temp.y+dir[i][]].ss='r';
}
}
}
} int main()
{
int i,j,sx1,sy1,sx2,sy2;
while(scanf("%d%d",&n,&m)!=EOF)
{
getchar();
memset(ans,,sizeof(ans));
for(i=;i<n;i++)
{
for(j=;j<m;j++)
{
scanf("%c",&bb[i][j].ss);
bb[i][j].value=;
bb[i][j].x=i;
bb[i][j].y=j;
if(bb[i][j].ss=='Y')
{
sx1=i;
sy1=j;
}
else if(bb[i][j].ss=='M')
{
sx2=i;
sy2=j;
}
}
getchar();
}
bfs1(bb,sx1,sy1);
for(i=;i<n;i++)
{
for(j=;j<m;j++)
{
bb[i][j].value=;
if(bb[i][j].ss=='d')
bb[i][j].ss='@';
else
if(bb[i][j].ss=='r')
bb[i][j].ss='.';
}
}
bfs1(bb,sx2,sy2);
int minm=INT_MAX;
for(i=;i<n;i++)
{
for(j=;j<m;j++)
{
if(bb[i][j].ss=='d'&&minm>ans[i][j])
minm=ans[i][j];
}
}
printf("%d\n",minm*);
}
return ;
}

HDUOJ----(2612)Find a way的更多相关文章

  1. HDU.2612 Find a way (BFS)

    HDU.2612 Find a way (BFS) 题意分析 圣诞节要到了,坤神和瑞瑞这对基佬想一起去召唤师大峡谷开开车.百度地图一下,发现周围的召唤师大峡谷还不少,这对基佬纠结着,该去哪一个...坤 ...

  2. HDUOJ ---1423 Greatest Common Increasing Subsequence(LCS)

    Greatest Common Increasing Subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536 ...

  3. HTML CSS 特殊字符表(转载)

    转载地址:http://blog.csdn.net/bluestarf/article/details/40652011 转载原文地址:http://zhengmifan.com/news/noteb ...

  4. 架构设计:负载均衡层设计方案(5)——LVS单节点安装

    1.概述 上篇文章<架构设计:负载均衡层设计方案(4)——LVS原理>(http://blog.csdn.net/yinwenjie/article/details/46845997),我 ...

  5. Microsoft SQL2000 错误代码 (@@error)

    Microsoft SQL 2000 错误代码(@@error) 0 操作成功完成.  1 功能错误.  2 系统找不到指定的文件.  3 系统找不到指定的路径.  4 系统无法打开文件.  5 拒绝 ...

  6. android -- 蓝牙 bluetooth (三)搜索蓝牙

    接上篇打开蓝牙继续,来一起看下蓝牙搜索的流程,触发蓝牙搜索的条件形式上有两种,一是在蓝牙设置界面开启蓝牙会直接开始搜索,另一个是先打开蓝牙开关在进入蓝牙设置界面也会触发搜索,也可能还有其它触发方式,但 ...

  7. js特殊符号(转)

    HTML有许多特殊的字符,您对此有多少了解?平时在WEB制作中,您又有用到多少?或者说你在平时使用之时,是否也会碰到,有许多特殊字符要如何打印出来?比如说“笑脸”,比如说“版权号”.要是你用时忘记了这 ...

  8. TCP/UDP端口列表(WIKIpedia)

    计算机之间依照互联网传输层TCP/IP协议不同的协议通信,都有不同的对应端口.所以,利用短信(datagram)的UDP,所采用的端口号码不一定和采用TCP的端口号码一样.以下为两种通信协议的端口列表 ...

  9. ZT android -- 蓝牙 bluetooth (三)搜索蓝牙

    android -- 蓝牙 bluetooth (三)搜索蓝牙 分类: Android的原生应用分析 2013-05-31 22:03 2192人阅读 评论(8) 收藏 举报 bluetooth蓝牙s ...

  10. 新旧图号(图幅号)转换/计算/检查,经纬度转换计算,C#代码

    图号(图幅号):地图图号是指为便于使用和管理,按照一定方法将各分幅地图进行的编号. 经常用到图号,但是在网上一直没有找到一个完整的图号转换程序,因此自己写了一个图号处理的库,分享出来.如有错误请指正. ...

随机推荐

  1. JQuery文件上传及以Base64字符串形式呈现图片

    一:上传之 首先,你必然得有一个 file input,如下: <td>     <img id="imgGif" style="display: no ...

  2. Android DiskLruCache 源代码解析 硬盘缓存的绝佳方案

    转载请标明出处: http://blog.csdn.net/lmj623565791/article/details/47251585: 本文出自:[张鸿洋的博客] 一.概述 依然是整理东西.所以最近 ...

  3. [置顶] Django 微信开发(一)——环境搭建

    Django 微信开发(一)——环境搭建 随着移动互联网时代的到来,微信——一个改变着我们生活的产品悄悄走近了我们的生活.我们不得不觉得自己很幸运,自己能在这个世界上遇到像QQ.微博.微信这样优秀的产 ...

  4. iOS开发-Get请求,Post请求,同步请求和异步请求

    标题中的Get和Post是请求的两种方式,同步和异步属于实现的方法,Get方式有同步和异步两种方法,Post同理也有两种.稍微有点Web知识的,对Get和Post应该不会陌生,常说的请求处理响应,基本 ...

  5. angular之interceptors拦截器

    <!DOCTYPE html> <html ng-app="nickApp"> <head> <meta charset="UT ...

  6. jwplayer 隐藏属性方法记载

    jwplayer().getPosition(): //播放了多少秒 jwplayer('playerdiv').play(); || jwplayer(0).play(true / false); ...

  7. vue-router路由模式详解

    一.路由模式解析 要讲vue-router的路由模式,首先要了解的一点就是路由是由多个URL组成的,使用不同的URL可以相应的导航到不同的位置. 如果有进行过服务器开发或者对http协议有所了解就会知 ...

  8. Dijkstra(迪杰斯特拉)算法求解最短路径

    过程 首先需要记录每个点到原点的距离,这个距离会在每一轮遍历的过程中刷新.每一个节点到原点的最短路径是其上一个节点(前驱节点)到原点的最短路径加上前驱节点到该节点的距离.以这个原则,经过N轮计算就能得 ...

  9. UVA 11464 Even Parity (独特思路)

    题意:有一个n*n的01矩阵,任务是把尽可能少的0变成1,使得每个元素的上.下.左.右元素之和为偶数. 思路:很容易想到的思路是枚举每个点是0还是1,因为n<=15,复杂度就是2^225显然TL ...

  10. python 初步学习

    疑惑1:windows下的python  如何设置显示汉字 推荐几个学习网址,也方便自己以后查看: http://pmghong.blog.51cto.com/3221425/d-10 www.w3c ...