hdu 2612(Find a way)(简单广搜)
Find a way
Time Limit : 3000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 30 Accepted Submission(s) : 14
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
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
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
Sample Input
4 4
Y.#@
....
.#..
@..M
4 4
Y.#@
....
.#..
@#.M
5 5
Y..@.
.#...
.#...
@..M.
#...#
Sample Output
66
88
66
#include <iostream>
#include<cstring>
#include<cstdio>
#include<deque>
#include<algorithm>
using namespace std;
int dr[][]={{,},{,},{-,},{,-} };
int n,m,i,j,num,x1,x2,y1,y2,ans;
int vis[][],a[][];
char mp[][];
struct node
{
int x,y,ti;
};
deque<node> s;
void bfs(int x,int y)
{
int t=num;
node p;
p.x=x;
p.y=y;
p.ti=;
s.clear();
s.push_back(p);
vis[x][y]=;
while(!s.empty())
{
node q=s.front();
for(i=;i<;i++)
{
int xx=q.x+dr[i][];
int yy=q.y+dr[i][];
if(xx>= && xx<n && yy>= && yy<m && mp[xx][yy]!='#')
if (!vis[xx][yy])
{
p.x=xx;
p.y=yy;
p.ti=q.ti+;
s.push_back(p);
vis[xx][yy]=;
if(mp[xx][yy]=='@')
{
a[xx][yy]+=p.ti;
ans=min(ans,a[xx][yy]);
t--;
}
if(t==) return;
}
}
s.pop_front();
}
}
int main()
{
while(~scanf("%d%d",&n,&m))
{
for(i=;i<n;i++)
{
scanf("%s",&mp[i]);
for(j=;j<m;j++)
if (mp[i][j]=='Y') x1=i,y1=j;
else if(mp[i][j]=='M') x2=i,y2=j;
else if (mp[i][j]=='@') {num++; a[i][j]=;}
}
memset(vis,,sizeof(vis));
bfs(x1,y1);
ans=;
memset(vis,,sizeof(vis));
bfs(x2,y2);
printf("%d\n",ans*);
}
return ;
}
hdu 2612(Find a way)(简单广搜)的更多相关文章
- hdu 5094 Maze 状态压缩dp+广搜
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4092176.html 题目链接:hdu 5094 Maze 状态压缩dp+广搜 使用广度优先 ...
- hdu 1195 Open the Lock(广搜,简单)
题目 猜密码,问最少操作多少次猜对,思路很简单的广搜,各种可能一个个列出来就可以了,可惜我写的很搓. 不过还是很开心,今天第一个一次过了的代码 #define _CRT_SECURE_NO_WARNI ...
- hdu 1180 诡异的楼梯(广搜,简单)
题目 挺简单的一道广搜题,只要用判断时间是偶数还是奇数就可以判断楼梯的方位,但是我这傻逼居然写了那么久啊那么久,我果然秀逗了,,,, #define _CRT_SECURE_NO_WARNINGS # ...
- hdu 1253 胜利大逃亡(广搜,队列,三维,简单)
题目 原来光搜是用队列的,深搜才用栈,我好白痴啊,居然搞错了 三维的基础的广搜题 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #in ...
- HDU 1548 A strange lift (广搜)
题目链接 Problem Description There is a strange lift.The lift can stop can at every floor as you want, a ...
- POJ 3126 Prime Path 简单广搜(BFS)
题意:一个四位数的质数,每次只能变换一个数字,而且变换后的数也要为质数.给出两个四位数的质数,输出第一个数变换为第二个数的最少步骤. 利用广搜就能很快解决问题了.还有一个要注意的地方,千位要大于0.例 ...
- POJ1376简单广搜
题意: 给你一个n*m的矩阵,然后给你机器人的起点和终点,还有起点的方向,然后每次机器人有两种操作,左右旋转90度,或者是朝着原来的方向走1,2或者3步,机器人再走的过程中不能碰到格子,也 ...
- (简单广搜) Ice Cave -- codeforces -- 540C
http://codeforces.com/problemset/problem/540/C You play a computer game. Your character stands on so ...
- HDU 1180 诡异的楼梯 (广搜)
题目链接 Problem Description Hogwarts正式开学以后,Harry发现在Hogwarts里,某些楼梯并不是静止不动的,相反,他们每隔一分钟就变动一次方向. 比如下面的例子里,一 ...
随机推荐
- tableviewcell滑动显示多个按钮UITableViewRowAction(转载)
demo截图 ios8 新的属性 typedef NS_ENUM(NSInteger, UITableViewRowActionStyle) { UITableViewRowActionStyleDe ...
- 关于MTK平台CC相关的Log查询
关于MTK平台CC相关的Log查询 在外场问题中,经常会出现通话相关的故障.这里简单总结一下通话相关log的分析点: 主叫方:主叫方,是指主动发起通话的一方. 初步定位问题, 用户发起通话时,AP端的 ...
- 【python问题系列--4】ValueError: operands could not be broadcast together with shapes (100,3) (3,1)
背景:dataMatrix是(100,3)的列表,labelMat是(1,100)的列表,weights是(3,1)的数组,属性如下代码所示: >>> import types> ...
- Javascript兑现图片预加载【回调函数,多张图片】 (转载)
Javascript实现图片预加载[回调函数,多张图片] 使用JS实现一组图片动画效果或者使用HTML5 Canvas渲染一系列图片等案例中,需要图片全部加载完成方可运行动画效果.此时程序中就会涉及多 ...
- Time complexity of ArrayList in Java
The size, isEmpty, get, set, iterator, and listIterator operations run in constant time. The add ope ...
- tree btn
@* <a href="javascript:void(0)" onclick="saveChecked()" ><img sr ...
- Codeforces Round 371 Div2 B.Passwords
原题: B. Passwords time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- 还原openstack配置文件的方法
cp -a /etc/neutron/neutron.conf /etc/neutron/neutron.conf.bakcp -a /etc/neutron/plugins/ml2/ml2_conf ...
- android开发技巧
1 Android去掉listView,gridView等系统自带阴影 当我们使用listView的时候,拉到顶,或是拉到底部的时候,我们会发现有系统自带的阴影效果出现,不同手机出现的颜色可能还会不一 ...
- Chapter 2 Open Book——19
He bent over and began scraping together a pile of the white mush. 他弯下腰,开始团起一个白色的雪球. "I'll see ...