(广搜) Find a way -- hdu -- 2612
链接:
http://acm.hdu.edu.cn/showproblem.php?pid=2612
Find a way
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 6718 Accepted Submission(s): 2236
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
88
66
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue> using namespace std; #define INF 0x3f3f3f3f
#define N 210 struct node
{
int x, y, step;
}; int n, m, a[N][N], dir[][]={{-,},{,},{,-},{,}};
char G[N][N];
int vis[N][N]; void BFS(node s, int num)
{
node p, q; queue<node>Q;
Q.push(s);
memset(vis, , sizeof(vis));
vis[s.x][s.y] = ; while(Q.size())
{
p = Q.front(), Q.pop(); if(G[p.x][p.y]=='@')
{
if(num==)
a[p.x][p.y] = p.step;
if(num==)
a[p.x][p.y] += p.step;
} for(int i=; i<; i++)
{
q.x = p.x + dir[i][];
q.y = p.y + dir[i][];
q.step = p.step + ; if(!vis[q.x][q.y] && q.x>= && q.x<n && q.y>= && q.y<m && G[q.x][q.y]!='#')
{ vis[q.x][q.y] = ;
Q.push(q);
}
}
}
} int main()
{
while(scanf("%d%d", &n, &m)!=EOF)
{
int i, j;
node Y, M; memset(a, , sizeof(a)); for(i=; i<n; i++)
{
scanf("%s", G[i]);
for(j=; j<m; j++)
{
if(G[i][j]=='Y')
Y.x=i, Y.y=j, Y.step=;
if(G[i][j]=='M')
M.x=i, M.y=j, M.step=;
}
} BFS(Y, );
BFS(M, ); int ans=INF; for(i=; i<n; i++)
for(j=; j<m; j++)
if(G[i][j]=='@' && vis[i][j])
ans = min(ans, a[i][j]); printf("%d\n", ans*); }
return ;
}
(广搜) Find a way -- hdu -- 2612的更多相关文章
- hdu 2612:Find a way(经典BFS广搜题)
Find a way Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu 5025 Saving Tang Monk 状态压缩dp+广搜
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4092939.html 题目链接:hdu 5025 Saving Tang Monk 状态压缩 ...
- hdu 5094 Maze 状态压缩dp+广搜
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4092176.html 题目链接:hdu 5094 Maze 状态压缩dp+广搜 使用广度优先 ...
- Combine String HDU - 5707 dp or 广搜
Combine String HDU - 5707 题目大意:给你三个串a,b,c,问a和b是不是恰好能组成c,也就是a,b是不是c的两个互补的子序列. 根据题意就可以知道对于c的第一个就应该是a第一 ...
- HDU 5652(二分+广搜)
题目链接:http://acm.hust.edu.cn/vjudge/contest/128683#problem/E 题目大意:给定一只含有0和1的地图,0代表可以走的格子,1代表不能走的格 子.之 ...
- hdu 1242:Rescue(BFS广搜 + 优先队列)
Rescue Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submis ...
- hdu 1195:Open the Lock(暴力BFS广搜)
Open the Lock Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- HDU 1253 (简单三维广搜) 胜利大逃亡
奇葩!这么简单的广搜居然爆内存了,而且一直爆,一直爆,Orz 而且我也优化过了的啊,尼玛还是一直爆! 先把代码贴上睡觉去了,明天再来弄 //#define LOCAL #include <ios ...
- hdu 1195 Open the Lock(广搜,简单)
题目 猜密码,问最少操作多少次猜对,思路很简单的广搜,各种可能一个个列出来就可以了,可惜我写的很搓. 不过还是很开心,今天第一个一次过了的代码 #define _CRT_SECURE_NO_WARNI ...
- hdu 1175 连连看 (广搜,注意解题思维,简单)
题目 解析见代码 #define _CRT_SECURE_NO_WARNINGS //这是非一般的最短路,所以广搜到的最短的路不一定是所要的路线 //所以应该把所有的路径都搜索出来,找到最短的转折数, ...
随机推荐
- ffmpeg C++程序编译时报__cxa_end_catch错误
解决方法在编译sh中加上 -lsupc++ 即可. 2.STL模块函数找不到,链接失败stdc++/include/bits/stl_list.h:466: error: undefined refe ...
- 桶排序与快速排序算法结合-python实现
#-*- coding: UTF-8 -*- import numpy as np from QuickSort import QuickSort def BucketSort(a, n): barr ...
- An Introduction to Greta
I was surprised by greta. I had assumed that the tensorflow and reticulate packages would eventually ...
- 事务的ACID和四个隔离级别
在实际的业务场景中,并发读写引出了和事务控制的需求.优秀的事务处理能力是关系型数据库(特别是oracle等商用RDBMS)相对于正当风口的NoSQL数据库的一大亮点.但这也从另一方面说明了事务控制的复 ...
- 8 ways to improve ASP.NET Web API performance
ASP.NET Web API is a great piece of technology. Writing Web API is so easy that many developers don’ ...
- [Python] numpy.Matrix
import numpy as np np.matrix('1, 2; 3, 4') #1, 2 #3, 4 np.matrix([[1,2],[3,4]]) #1, 2 #3, 4
- html链接路径
html链接的相对路径与绝对路径 绝对路径 完整的一个路径就是绝对路径,即包含schema://host[:port#]/path/.../[?query-string][#anchor] 例:htt ...
- linux中grep工具
正则表达式 以前我们用grep在一个文件中找出包含某些字符串的行,比如在头文件中找出一个宏定义.其实grep还可以找出符合某个模式(Pattern)的一类字符串.例如找出所有符合xxxxx@xxxx. ...
- 「小程序JAVA实战」小程序查看视频发布者信息(64)
转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxuchakanshipinfabuzhexinxi63/ 当我们点击右下 ...
- 【python 】Requests 库学习笔记
概览 实例引入 import requests response = requests.get('https://www.baidu.com/') print(type(response)) prin ...