hdu 2612
Find a way
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3451 Accepted Submission(s):
1128
hometown Ningbo at finally. Leave Ningbo one year, yifenfei have many people to
meet. Especially a good friend Merceki.
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
both yifenfei and Merceki to arrival one of KFC.You may sure there is always
have a KFC that can let them meet.
4 4
Y.#@
....
.#..
@..M
4 4
Y.#@
....
.#..
@#.M
5 5
Y..@.
.#...
.#...
@..M.
#...#
6 5
Y.@#.
.#.#.
.#.#.
.#.#.
.#.#.
##M..
77
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<queue>
using namespace std; int n,m;
int yx,yy,mx,my;
int to[][]={{,},{,},{-,},{,-}};
char a[][];
int time[][][];
bool hash[][][];
bool flag;
struct node
{
int x,y;
int time;
};
queue<node>Q[]; int Min(int x,int y)
{
return x>y? y:x;
}
bool pd(node &t)
{
if(t.x>=&&t.x<=n && t.y>=&&t.y<=m && a[t.x][t.y]!='#')return false;
return true;
}
int bfs(int x)
{
int i,hxl=;
node t,cur; while(!Q[x].empty())
{
cur=Q[x].front();
Q[x].pop();
for(i=;i<;i++)
{
t=cur;
t.x=t.x+to[i][];
t.y=t.y+to[i][];
t.time++;
if(pd(t))continue;
if(hash[x][t.x][t.y])continue;
hash[x][t.x][t.y]=true;
time[x][t.x][t.y]=t.time;
if(x== && a[t.x][t.y]=='@')
{
hxl=Min(hxl,time[x^][t.x][t.y]+time[x][t.x][t.y]);
}
Q[x].push(t);
}
}
return hxl;
}
void dbfs()
{
int ans=;
node t;
t.x=yx;
t.y=yy;
t.time=;
Q[].push(t);
hash[][yx][yy]=true; t.x=mx;
t.y=my;
t.time=;
Q[].push(t);
hash[][mx][my]=true; bfs();
ans = bfs();
printf("%d\n",ans*);
}
int main()
{
int i,j;
while(scanf("%d%d",&n,&m)>)
{
for(i=;i<=n;i++)
scanf("%s",a[i]+);
memset(hash,false,sizeof(hash));
memset(time,,sizeof(time));
for(i=;i<=n;i++)
for(j=;j<=m;j++){
if(a[i][j]=='Y'){
yx=i;
yy=j;
}
else if(a[i][j]=='M'){
mx=i;
my=j;
}
}
while(!Q[].empty()){
Q[].pop();
}
while(!Q[].empty()){
Q[].pop();
}
flag=false;
dbfs();
}
return ;
}
hdu 2612的更多相关文章
- HDU 2612 Find a way(找条路)
HDU 2612 Find a way(找条路) 00 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem ...
- HDU.2612 Find a way (BFS)
HDU.2612 Find a way (BFS) 题意分析 圣诞节要到了,坤神和瑞瑞这对基佬想一起去召唤师大峡谷开开车.百度地图一下,发现周围的召唤师大峡谷还不少,这对基佬纠结着,该去哪一个...坤 ...
- BFS(最短路) HDU 2612 Find a way
题目传送门 /* BFS:和UVA_11624差不多,本题就是分别求两个点到KFC的最短路,然后相加求最小值 */ /***************************************** ...
- HDU 2612 Find a way(双向bfs)
题目代号:HDU 2612 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2612 Find a way Time Limit: 3000/1000 M ...
- hdu 2612 Find a way
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2612 Find a way Description Pass a year learning in H ...
- HDU 2612 - Find a way - [BFS]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2612 Problem DescriptionPass a year learning in Hangz ...
- HDU 2612 Find a way bfs 难度:1
http://acm.hdu.edu.cn/showproblem.php?pid=2612 bfs两次就可将两个人到达所有kfc的时间求出,取两人时间之和最短的即可,这个有点不符合实情,题目应该出两 ...
- (广搜) Find a way -- hdu -- 2612
链接: http://acm.hdu.edu.cn/showproblem.php?pid=2612 Find a way Time Limit: 3000/1000 MS (Java/Others) ...
- HDU - 2612 Find a way 【BFS】
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=2612 题意 有两个人 要去一个城市中的KFC 一个城市中有多个KFC 求两个人到哪一个KFC的总时间最 ...
- HDU 2612 (BFS搜索+多终点)
题目链接: http://poj.org/problem?id=1947 题目大意:两人选择图中一个kfc约会.问两人到达时间之和的最小值. 解题思路: 对于一个KFC,两人的BFS目标必须一致. 于 ...
随机推荐
- CentOS IPv6设置
1)/etc/sysconfig/network 打开/关闭网络配置 添加: NETWORKING_IPV6=yes 打开IPv6 IPV6_AUTOCONF=no 如果不喜欢自动获 ...
- jquery判断滚动到某个div显示底部按钮
判读滚动某个div显示底部按钮 <!DOCTYPE html> <html lang="zh-CN"> <head> <meta char ...
- jzoj100031
這題是結論題 好玄學,不懂 代碼: #include<bits/stdc++.h> using namespace std; struct no{ int v,p; bool operat ...
- hdu5833----高斯消元
题目大意: 给你n个整数,从中选一些数,他们的乘积为一个完全平方数 问有多少种这样的方式,已知这些数的素因素不超过2000. 思路: 一个完全平方数素因素的个数肯定是偶数个. 我们只要从n个数中选取所 ...
- 重读源码,见证HashMap以及它的朋友们的骚操作
一.Getting Start Again and again,until you master it.早在接触java.util包的时候,我们都会去阅读ArrayList,甚至也会去阅读HashMa ...
- day55 linux 基础以及系统优化
Linux系统基础优化及常用命令 Linux基础系统优化 引言没有,只有一张图. Linux的网络功能相当强悍,一时之间我们无法了解所有的网络命令,在配置服务器基础环境时,先了解下网络参数设定命令 ...
- pythonweb框架Flask学习笔记02-一个简单的小程序
#-*- coding:utf-8 -*- #导入了Flask类 这个类的实例将会是我们的WSGI应用程序 from flask import Flask #创建一个Flask类的实例 第一个参数是应 ...
- Anaconda 入门详解
Anaconda Anaconda简介 Anaconda是一个免费开源的Python和R语言的发行版本,用于计算科学(数据科学.机器学习.大数据处理和预测分析),Anaconda致力于简化包管理和部署 ...
- Mysql 5.7版本安装:mysql 服务无法启动。
一.解压文件 下载好MySQL后,解压到D盘下,也可以根据个人喜好解压在其他盘符的路径下,解压后的路径是:D:\mysql-5.7.17-winx64.解压好后不要太兴奋,需要配置默认文件呢! 二. ...
- SpringAOP-切面优先级
项目中有两个切面,这两个切面都作用于同一个方法,哪个先执行哪个后执行呢,所以要定义一个切面的优先级 import java.util.Arrays; import org.aspectj.lang.J ...