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这两天总是因为一些小错误耽误时间,我希望自己可以细心点.珍惜 ...
随机推荐
- IT人学习方法论(二):学习误区
之前我们讨论了“学什么”的问题,今天我们来谈一谈“怎么学”的问题.磨刀不误砍柴工,我们要提高学习效率,首先需要找到自己学习方法上的误区. 一些常见的学习方法误区 1)资料导向型 现在就停止阅读这篇文章 ...
- Linux下多窗口分屏式终端--Terminator
很不错的分屏插件终端:https://pkgs.org/centos-6/repoforge-i386/terminator-0.95-3.el6.rf.noarch.rpm.html
- Java内存泄露的理解与解决
依赖于引用判断的内存管理机制 Java中对内存对象的访问,使用的是引用的方式.在Java代码中我们维护一个内存对象的引用变量,通过这个引用变量的值,我们可以访问到对应的内存地址中的内存对象空间.在Ja ...
- 设计模式学习之观察者模式(Observer,行为型模式)(7)
1.观察者模式又叫做发布-订阅模式. 2.观察者模式定义了一种一对多的依赖关系,让多个观察者对象同时监听某一个主题对象.这个主题对象在状态发生变化时,会通知所有观察者对象,使它们能够自动更新自己. 3 ...
- 10g 11g配置Logical Standby
1.创建一个物理Standby数据库 详细见11g Physical Standby配置 2.Standby数据库取消managed recovery ALTER DATABASE RECOVER ...
- Ubuntu / Win7 安装db2 v10.5
抓紧下载v10.5fp1_linuxx64_expc.tar.gz到~/Downloads/java_softcd java_softtar xf v10.5fp1_linuxx64_expc.tar ...
- JqueryEasyUI 解决IE下加载时页面错乱的问题 分类: JavaScript JqueryEasyUI 2014-09-20 09:50 545人阅读 评论(1) 收藏
问题描述: 一直觉得jqueryeasyui在IE下的渲染效果不大好,尤其刚进入页面时的加载,页面会出现布局错乱,虽然是一闪而过,但是给用户的体验不好: 可以通过在页面onload时,增加一个遮罩层, ...
- 使用pl/sql監控PROCEDURE執行時間
創建表 CREATE TABLE PROCESS_TIMING_LOG ( PROCESS_NAME VARCHAR2(50 BYTE), EXECUTION_DATE D ...
- web.xml中同一servlet/filter配置多个url-pattern
转自:http://blog.sina.com.cn/s/blog_4c2c2a0c0100dh67.html 若你的servlet要多个地址,或你的filter需要过滤不同的url如有*.jsp,* ...
- Codeforces Round #229 (Div. 2) C. Inna and Candy Boxes 树状数组s
C. Inna and Candy Boxes Inna loves sweets very much. She has n closed present boxes lines up in a ...