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. 完全理解Gson(1):简单入门

    GSON是Google开发的Java API,用于转换Java对象和Json对象.本文讨论并提供了使用API的简单代码示例.更多关于GSON的API可以访问:http://sites.google.c ...

  2. 如何解决Maven速度慢

    注:oschina已失效 Maven 远程仓库 <mirror> <id>ui</id> <mirrorOf>central</mirrorOf& ...

  3. nginx: [emerg] "proxy_cache_path" directive is not allowed here in /usr/local/nginx/conf/nginx.conf:43

    1.它只能使用于http{  }部分,把proxy_cache_path放置于http部分即可解决此问题.注意图示的上下文

  4. OpenCV学习(40) 人脸识别(4)

    在人脸识别模式类中,还实现了一种基于LBP直方图的人脸识别方法.LBP图的原理参照:http://www.cnblogs.com/mikewolf2002/p/3438698.html       在 ...

  5. [转贴] 数字证书及 CA 的扫盲介绍

    [略有删节] 为了达到普及的效果,俺会尽量用比较浅显,非技术的语言来讲清楚. ★先说一个通俗的例子 考虑到证书体系的相关知识比较枯燥.晦涩.俺先拿一个通俗的例子来说事儿.   ◇普通的介绍信 想必大伙 ...

  6. 以ScaleIO 1.30为后端存储运行微软服务器软件SQL Server 2014, SharePoint 2013, Exchange 2013的解决方案

    EMC新发布了以ScaleIO 1.30为后端存储来运行SQL, SharePoint, Exchange的解决方案白皮书.   下面的页面中有简要的介绍和整篇文档PDF的下载. https://co ...

  7. 11个JavaScript颜色选择器插件

    几年前,很难找到一个合适的颜色选择器.正好看到很多不错的JavaScript颜色选择器插件,故而把这些编译汇总.在本文,Web设计师和开发人员 Kevin Liew 选取了11个相应插件,有些会比较复 ...

  8. Linux之nohup命令:实现退出终端后程序继续后台运行

    转自:http://tech.ccidnet.com/art/302/20070618/1115599_1.html 简单而有用的nohup命令在UNIX/LINUX中,普通进程用&符号放到后 ...

  9. Linux History安全问题【保存记录防止删除】+完善Linux/UNIX审计 将每个shell命令记入日志

    2011-09-27 22:11:51|  分类: rhel5_033|举报|字号 订阅       Linux利用PROMPT_COMMAND实现审计功能 这个系统审计,记录什么用户,在什么时间,做 ...

  10. select设置高度的兼容问题

    在IE678下,我们给select设置高度的话,里面的option无法居中,折中的兼容方式就是,我们给select的border:0:外面套一层div,这个div给他设置padding,让select ...