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这两天总是因为一些小错误耽误时间,我希望自己可以细心点.珍惜 ...
随机推荐
- phpexcel中文教程-设置表格字体颜色背景样式、数据格式、对齐方式、添加图片、批注、文字块、合并拆分单元格、单元格密码保护
转:http://www.cnblogs.com/huangcong/p/3687665.html 首先到phpexcel官网上下载最新的phpexcel类,下周解压缩一个classes文件夹,里面包 ...
- Android Studio 配置
Android配置:[转]原地址:http://www.cnblogs.com/smyhvae/p/4022844.html [开发环境] 物理机版本:Win7旗舰版(64位) Android Stu ...
- 【Java EE 学习 21 上】【其它类型的监听器】【使用HttpSessionActivationListener监听session的活化和钝化】
一.ServletContextListener Method Summary void contextDestroyed(ServletContextEvent sce) R ...
- 没有VisualStudio也要HelloWorld
前言 在博客园看到Artech的通过3个Hello World应用来了解ASP.NET 5应用是如何运行的(1)这篇文章,于是想跟着教程学习一下.说来惭愧,这篇文章发布于2014年12月,我在2016 ...
- html5 Canvas绘制图形入门详解
html5,这个应该就不需要多作介绍了,只要是开发人员应该都不会陌生.html5是「新兴」的网页技术标准,目前,除IE8及其以下版本的IE浏览器之外,几乎所有主流浏览器(FireFox.Chrome. ...
- Oracle里SID、SERVICE_NAME
本文仅用作备忘,无实际指导意义,逻辑略混乱. 1.命令show parameter name; SQL> show parameter name; NAME TYPE VALUE ------- ...
- Oracle【IT实验室】数据库备份与恢复之五:Flashback
Flashback在开发环境(有时生产环境的特殊情况下)是很有用的一个工具. 5.1 9i Flashback 简介 5.1.1 原理 当数据 update 或 delete ...
- 豆瓣的账号登录及api操作
.douban.php <?php /** * PHP Library for douban.com * * @author */ class doubanPHP { function __co ...
- Error: Could not find or load main class test.EditFile
今天写了一个简单的小程序,运行之后发现Error: Could not find or load main class test.EditFile,项目无法启动.删除main中的所有内容之后依旧提示该 ...
- Codeforces Round #248 (Div. 2) C. Ryouko's Memory Note
题目链接:http://codeforces.com/contest/433/problem/C 思路:可以想到,要把某一个数字变成他的相邻中的数字的其中一个,这样总和才会减少,于是我们可以把每个数的 ...