hdu2612 Find a way
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
#include<iostream>
#include<queue>
#include<cstring>
using namespace std;
int m,n;
int vis[][];
char mapp[][];
int dis[][][];
int dir[][] = {,,,,-,,,-},flag;
struct node{
int x;
int y;
int step;
};
bool judge(int x,int y)
{
if(x>=&&x<m&&y>=&&y<n&&mapp[x][y]!='#'&&vis[x][y]==)
return ;
return ;
}
int BFS(int x,int y)
{
queue<node>q;
node now,next;
now.x=x;
now.y=y;
now.step=;
vis[x][y]=;
q.push(now);
while(!q.empty())
{
now=q.front();
q.pop();
next.step=now.step+;
for(int i=;i<;i++)
{
next.x=now.x+dir[i][];
next.y=now.y+dir[i][];
if(judge(next.x,next.y))
{
vis[next.x][next.y]=;
if(mapp[next.x][next.y]=='@')
dis[next.x][next.y][flag]=next.step;
q.push(next);
}
}
}
}
int main()
{
while(cin>>m>>n)
{
int min=;
for(int i=;i<m;i++)
for(int j=;j<n;j++)
dis[i][j][]=dis[i][j][]=min;
for(int i=;i<m;i++)
for(int j=;j<n;j++)
{
cin>>mapp[i][j];
}
for(int i=;i<m;i++)
for(int j=;j<n;j++)
{
if(mapp[i][j]=='Y')
{
flag=;
memset(vis,,sizeof(vis));
BFS(i,j);
}
else if(mapp[i][j]=='M')
{
flag=;
memset(vis,,sizeof(vis));
BFS(i,j);
}
}
for(int i=;i<m;i++)
for(int j=;j<n;j++)
if(mapp[i][j]=='@' && min>dis[i][j][]+dis[i][j][])
min=dis[i][j][]+dis[i][j][];
printf("%d\n",min*);
}
}
hdu2612 Find a way的更多相关文章
- 简单bfs(hdu2612)
#include<stdio.h>#include<string.h>#include<queue>#define INF 0x3f3f3f3fusing name ...
- hdu2612.。。。
原题链接 水了一天bfs了 题意:2个人分别从Y,M出发,到达其中任意一个“@” (图中有多个“@”点),2人到达的必须是同一个“@”点,求最短的路程和 思路:bfs搜2次,用一个2维数组记录到达各个 ...
- 暑假集训(1)第四弹 -----Find a way(Hdu2612)
Description Pass a year learning in Hangzhou, yifenfei arrival hometown Ningbo at finally. Leave Nin ...
- hdu2612(bfs)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2612 题意:求2个点到任意一个KFC的距离之和,使其最小. 分析:由两个点出发分别两次bfs,求得到每 ...
- hdu2612 Find a way BFS
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2612 思路: 裸的BFS,对于Y,M分别进行BFS,求出其分别到达各个点的最小时间: 然后对于@的点, ...
- HDU-2612.Find way .(不同起点不同终点的BFS)
我要被这个好用的memset气死了...... 真香 #include <cstring> #include <string> int main () { ]; memset( ...
- Hdu2612 Find a way 2017-01-18 14:52 59人阅读 评论(0) 收藏
Find a way Time Limit : 3000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Su ...
- HDU2612(KB1-N)
Find a way Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU2612 -暑假集训-搜索进阶N
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82828#problem/N这两天总是因为一些小错误耽误时间,我希望自己可以细心点.珍惜 ...
随机推荐
- C#学习笔记----AppDomain应用程序域
使用.Net建立的可执行程序*.exe,并没有直接承载到进程当中,而是承载到应用程序域(AppDomain)当中.应用程序域是.Net引入的一个新概念,它比进程所占用的资源要少,可以被看做是一个轻量级 ...
- jQuery学习笔记---兄弟元素、子元素和父元素的获取
我们这里主要总结jQuery中对某元素的兄弟元素.子元素和父元素的获取,原声的Javascript代码对这些元素的获取比较麻烦一些,而jQuery正好对这些方法进行封装,让我们更加方便的对这些元素进行 ...
- 在ubuntu上搭建开发环境1---在windows7的基础上在安装ubuntu(双系统)
转载:http://jingyan.baidu.com/article/60ccbceb18624464cab197ea.html 当需要频繁使用ubuntu时,vmware虚拟机下运行ubuntu, ...
- 说说JSON和JSONP,也许你会豁然开朗,含jQuery用例 分类: JavaScript 2014-09-23 10:41 218人阅读 评论(1) 收藏
前言: 由于Sencha Touch 2这种开发模式的特性,基本决定了它原生的数据交互行为几乎只能通过AJAX来实现. 当然了,通过调用强大的PhoneGap插件然后打包,你可以实现100%的Sock ...
- PING命令入门详解
转自:http://www.linkwan.com/gb/tech/htm/928.htm 1.Ping的基础知识 ping命令相信大家已经再熟悉不过了,但是能把ping的功能发挥到最大的人却并不是很 ...
- CRC校验(转)
CRC即循环冗余校验码(Cyclic Redundancy Check[1] ):是数据通信领域中最常用的一种差错校验码,其特征是信息字段和校验字段的长度可以任意选定.循环冗余检查(CRC)是一种数据 ...
- 在Salesforce中将 Decimal 数据转换成美元格式
闲言少叙,直接上代码(Apex Class 中的方法): private string ConvertToMoneyFormat(decimal price){ if (price == null | ...
- indeterminateDrawable
Android原生控件只有横向进度条一种,而且没法变换样式,比如原生rom的样子很丑是吧,当伟大的产品设计要求更换前背景,甚至纵向,甚至圆弧状的,咋办,比如ok,我们开始吧: 一)变换前背景 先来看看 ...
- 对于c语言int类型和float,以及double类型表示范围的计算
首先说一下我原来错误的认识 int是32个bit, 如果我们把第一位理解为符号位,那么很显然int的范围是-(2^31-1)~2^31-1 但是实际上我们都知道int的最小值是-2^31次.. 为什么 ...
- 时间和地域三级联动选择器(Android-PickerView-master)
先附上下载和效果展示地址 https://github.com/saiwu-bigkoo/Android-PickerView 之后说一下程序依赖后会遇到的问题Error:(2, 0) Plugin ...