hdu2612.。。。
水了一天bfs了
题意:2个人分别从Y,M出发,到达其中任意一个“@” (图中有多个“@”点),2人到达的必须是同一个“@”点,求最短的路程和
思路:bfs搜2次,用一个2维数组记录到达各个“@”的距离之和 再遍历求最小的(用一个数组就可以的原因是Y可以到达的地方M一定也能到达,因为Y,M必然可以相遇,所以Y和M必然是连通,一开始还怀疑了一下自己)
#include "map"
#include "queue"
#include "math.h"
#include "stdio.h"
#include "string.h"
#include "iostream"
#include "algorithm"
19:01:0019:01:162016-08-05#define abs(x) x > 0 ? x : -x
#define max(a,b) a > b ? a : b
#define min(a,b) a < b ? a : b using namespace std; int d[][] = {{,},{,},{,-},{-,}};
int Map[][],l[][];
bool vis[][]; struct Node
{
int xx,yy;
int step;
}; void Bfs(int x,int y)
{
memset(vis,,sizeof(vis));
Node now,next;
queue<Node>Q; now.xx = x;
now.yy = y;
now.step = ;
vis[x][y] = ; Q.push(now); while(!Q.empty())
{
now = Q.front();
Q.pop(); if(Map[now.xx][now.yy]==)
l[now.xx][now.yy] += now.step; for(int i=; i<; i++)
{
next.xx = now.xx + d[i][];
next.yy = now.yy + d[i][];
next.step = now.step + ; if(Map[next.xx][next.yy]!= && !vis[next.xx][next.yy])
{
vis[next.xx][next.yy] = ;
Q.push(next);
}
}
}
} int main()
{
int x1,y1,x2,y2,n,m,ans,i,j;
char c;
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(Map,,sizeof(Map));
memset(l,,sizeof(l));
for(i=; i<=n; i++)
{
getchar();
for(j=; j<=m; j++)
{
scanf("%c",&c);
if(c=='.')
Map[i][j] = ;
if(c=='#')
Map[i][j] = ;
if(c=='Y')
{
Map[i][j] = ;
x1 = i,y1 = j;
}
if(c=='M')
{
Map[i][j] = ;
x2 = i,y2 = j;
}
if(c=='@')
Map[i][j] = ;
}
}
Bfs(x1,y1);
Bfs(x2,y2); ans = ;
for(i=; i<=n; i++)
for(j=; j<=m; j++)
{
if(l[i][j]!=)
ans = min(ans,l[i][j]);
}
printf("%d\n",ans*);
}
return ;
}
hdu2612.。。。的更多相关文章
- .net 项目 调用webservice 出错,异常信息:对操作“xxx”的回复消息正文进行反序列化时出错。解决方案。
项目运行好好的,增加并更新WebService后,出错,捕获异常信息为:对操作“xxx”的回复消息正文进行反序列化时出错.解决方案. 认真分析异常信息后,得到关键提醒: {"读取 XML 数 ...
- spring mvc 错误摘要--。位。
1....identifier of an instance of org.szgzw.ent.profile.baseinfo.enterprise.EnterpriseEntity was alt ...
- 普天同庆,微博开通,从今以后,努力用功! 狗屎一样的顺口溜!Q狗屎!!狗屎。。。。。 测试。。测试。。。没刷过微博。屯里来的。看看啥效果
普天同庆,微博开通,从今以后,努力用功! 狗屎一样的顺口溜!Q狗屎!!狗屎..... 测试..测试...没刷过微博.屯里来的.看看啥效果
- day22 模块最后的补充。包。
前一天内容复习: # def func(): # a # # def main(): # func() # # try: # main() # except: # pass # raise NameE ...
- u3d 楼梯,圆环,椭圆,直线运动。世界坐标。点击。U3d stair, ring, ellipse, linear motion.World coordinates.Click .
u3d 楼梯,圆环,椭圆,直线运动.世界坐标.点击. U3d stair, ring, ellipse, linear motion.World coordinates.Click . 作者:韩梦飞沙 ...
- make: *** /lib/modules/3.10.0-327.el7.x86_64/build: 没有那个文件或目录。 停止。
1.问题: [root@localhost]# make make -C /lib/modules/-.el7.x86_64/build M=/home/csri/poc/adore modules ...
- 今天开始每天一点ffmpeg知识。千里之行 。
今天开始每天一点ffmpeg知识.千里之行 .
- 【lunux-make: *** 没有规则可以创建目标“install”。 停止。问题】
[root@localhost nginx-1.8.0]# make installmake: *** 没有规则可以创建目标“install”. 停止.
- Makefile:1: *** 多个目标匹配。 停止。
以下是我自己写的Makefile 文件: .SUFFIXES:.c .o CC = gcc SRCS = stat.c OBJS = $(SRCS:.c=.o) EXEC = test start:$ ...
- 网站报"组策略阻止了这个程序。要获取详细信息,请与系统管理员联系。"错误。
今天将一个测试的网站发布到阿里云虚拟主机后,访问网站报“组策略阻止了这个程序.要获取详细信息,请与系统管理员联系.”错误.如下: 但是这个错误在本地调试时是没有的. 经过调查,原来罪魁祸首是 Micr ...
随机推荐
- Ubuntu14.04LTS系统输入法的安装
由于安装的时候选择的是英文版,所以一进入系统问题就来了:无法输入中文. 我记得自己直接选的输入法是pinyin那个 在网上看到别人到blog,直接转过来吧,只为自己收藏下,如有需要请联系原作者. 转载 ...
- leetcode 1_2_3_7
来自lknny.com,欢迎交流学习!点击 tags: [leetcode,algorithm] categories: algorithm --- Two Sum Given an array of ...
- Codeforces Round #369 (Div. 2) C. Coloring Trees DP
C. Coloring Trees ZS the Coder and Chris the Baboon has arrived at Udayland! They walked in the pa ...
- ios调用系统导航
#import "ViewController.h" #import <MapKit/MapKit.h> @interface ViewController () @p ...
- 智能车学习(五)—— dac学习
一.代码共享: 1.dac.h #ifndef DAC_H_ #define DAC_H_ #include "common.h" // 2.2 DAC控制寄存器0 位定义 #de ...
- 编译报错dereferencing pointer to incomplete type
关于编译报错“dereferencing pointer to incomplete type... 多是没找到结构体的定义,可以在本地复制其定义试试. 参考: http://my.oschina.n ...
- constructor
function Person(name){ this.name = name; } Person.prototype = { constructor : Person, sayName : func ...
- TeeChart Pro 5.0
这是Delphi7自带例子 C:\Program Files\Borland\Delphi7\Demos\TeeChart 以下为翻译的文字,有部分不准确. TeeChart Pro 5.0是一个库 ...
- 【bzoj2440】【bzoj3994】莫比乌斯反演学习
哇..原来莫比乌斯代码这么短..顿时感觉逼格-- 写了这道题以后,才稍稍对莫比乌斯函数理解了一些 定理:和是定义在非负整数集合上的两个函数,并且满足条件,那么我们得到结论 在上面的公式中有一个函数,它 ...
- http://jingyan.baidu.com/article/2009576193ee38cb0721b416.html
http://jingyan.baidu.com/article/2009576193ee38cb0721b416.html