博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 2612 Find a way(两次bfs)
阅读量:4139 次
发布时间:2019-05-25

本文共 2356 字,大约阅读时间需要 7 分钟。

Find a way

Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 6785 Accepted Submission(s): 2267
Problem Description
Pass a year learning in Hangzhou, yifenfei arrival 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.
Input
The input contains multiple test cases.
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
For each test case output the minimum total time that both yifenfei and Merceki to arrival one of KFC.You may sure there is always have a KFC that can let them meet.
Sample Input
4 4Y.#@.....#..@..M4 4Y.#@.....#..@#.M5 5Y..@..#....#...@..M.#...#
Sample Output
668866  
/*分析:直接想到两次bfs然后扫一次求点最小 有个重点的地方!就是那点必须是两个人都能走到的!!wa了2次 */#include
#include
#include
#include
#include
using namespace std;const int N=200+5;char map[N][N];bool book[N][N];short ok[N][N];int re[N][N];int n,m;struct Node{ int x,y,step;}node,tmp;queue
q;int step[4][2]={ {1,0},{0,1},{-1,0},{0,-1}};inline void bfs(int bx,int by){ memset(book,0,sizeof(book)); while(!q.empty()) q.pop(); node.x=bx; node.y=by; node.step=0; q.push(node); book[bx][by]=1; while(!q.empty()){ node=q.front(); q.pop(); if(map[node.x][node.y]=='@'){ ok[node.x][node.y]++; re[node.x][node.y]+=node.step; } int i; for(i=0;i<4;i++){ int a=node.x+step[i][0]; int b=node.y+step[i][1]; if(a<0||a>=n||b<0||b>=m||book[a][b]||map[a][b]=='#' /* ||map[a][b]=='M'||map[a][b]=='Y'*/) continue; book[a][b]=1; tmp.x=a; tmp.y=b; tmp.step=node.step+11; q.push(tmp); } }}int main(){ int i,j,x1,y1,x2,y2; while(scanf("%d%d",&n,&m)==2){ memset(re,0,sizeof(re)); memset(ok,0,sizeof(ok)); for(i=0;i
re[i][j]) small=re[i][j]; printf("%d\n",small); } return 0;}

转载地址:http://jfmvi.baihongyu.com/

你可能感兴趣的文章
IntelliJ IDAE 2018.2 汉化
查看>>
基于S5PV210的uboot移植中遇到的若干问题记录(一)DM9000网卡移植
查看>>
Openwrt源码下载与编译
查看>>
我和ip_conntrack不得不说的一些事
查看>>
Linux 查看端口使用情况
查看>>
文件隐藏
查看>>
两个linux内核rootkit--之二:adore-ng
查看>>
两个linux内核rootkit--之一:enyelkm
查看>>
关于linux栈的一个深层次的问题
查看>>
rootkit related
查看>>
mysql-应用案例-视图的应用
查看>>
什么是虚拟机?
查看>>
Microsoft Visual C++ 和 Borland C++ Builder 之比较
查看>>
C++ Builder 中定时器的应用
查看>>
Notepad++ 是程序员的必备利器之一
查看>>
Source Insight : 程序员最得心应手的代码阅读和编辑工具(高效)
查看>>
如何用C语言获取系统的用户登录名?
查看>>
如何用C语言获取系统的sid信息?
查看>>
C/C++中如何写长串(字符数组的拼接)?
查看>>
strtok函数真是个蹩脚而又恶心的设计(千万不要嵌套使用strtok函数)
查看>>