HDU2612(KB1-N)
Find a way
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 12795 Accepted Submission(s): 4105
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
Y.#@
....
.#..
@..M
4 4
Y.#@
....
.#..
@#.M
5 5
Y..@.
.#...
.#...
@..M.
#...#
Sample Output
88
66
Author
Source
//2017-02-28
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue> using namespace std; struct node{
int x, y, step;
void setNode(int x, int y, int step){
this->x = x;
this->y = y;
this->step = step;
}
};
char grid[][];
bool book[][];
int Ydis[][], Mdis[][];
int n, m;
int dx[] = {, , , -};
int dy[] = {, , -, };
const int inf = 0x3f3f3f3f; void bfs(int sx, int sy)
{
node tmp;
tmp.setNode(sx, sy, );
queue<node> q;
q.push(tmp);
memset(book, , sizeof(book));
book[sx][sy] = ;
int x, y, step;
while(!q.empty())
{
x = q.front().x;
y = q.front().y;
step = q.front().step;
q.pop();
if(grid[x][y] == '@'){
if(grid[sx][sy] == 'Y')Ydis[x][y] = step;
else Mdis[x][y] = step;
}
for(int i = ; i < ; i++)
{
int nx = x + dx[i];
int ny = y + dy[i];
if(nx>=&&nx<n&&ny>=&&ny<m&&!book[nx][ny]&&grid[nx][ny]!='#'){
book[nx][ny] = ;
tmp.setNode(nx, ny, step+);
q.push(tmp);
}
}
}
} int main()
{
while(cin>>n>>m)
{
for(int i = ; i < n; i++)
for(int j = ; j < m; j++)
cin>>grid[i][j];
memset(Ydis, inf, sizeof(Ydis));
memset(Mdis, inf, sizeof(Mdis));
for(int i = ; i < n; i++)
for(int j = ; j < m; j++)
if(grid[i][j] == 'Y' || grid[i][j] == 'M')
bfs(i, j);
int ans = inf;
for(int i = ; i < n; i++)
for(int j = ; j < m; j++)
if(grid[i][j] == '@' && ans > Ydis[i][j]+Mdis[i][j])
ans = Ydis[i][j] + Mdis[i][j];
cout<<*ans<<endl;
} return ;
}
HDU2612(KB1-N)的更多相关文章
- 简单bfs(hdu2612)
#include<stdio.h>#include<string.h>#include<queue>#define INF 0x3f3f3f3fusing name ...
- hdu2612 Find a way
Problem Description Pass a year learning in Hangzhou, yifenfei arrival hometown Ningbo at finally. L ...
- hdu2612.。。。
原题链接 水了一天bfs了 题意:2个人分别从Y,M出发,到达其中任意一个“@” (图中有多个“@”点),2人到达的必须是同一个“@”点,求最短的路程和 思路:bfs搜2次,用一个2维数组记录到达各个 ...
- 暑假集训(1)第四弹 -----Find a way(Hdu2612)
Description Pass a year learning in Hangzhou, yifenfei arrival hometown Ningbo at finally. Leave Nin ...
- hdu2612(bfs)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2612 题意:求2个点到任意一个KFC的距离之和,使其最小. 分析:由两个点出发分别两次bfs,求得到每 ...
- hdu2612 Find a way BFS
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2612 思路: 裸的BFS,对于Y,M分别进行BFS,求出其分别到达各个点的最小时间: 然后对于@的点, ...
- HDU-2612.Find way .(不同起点不同终点的BFS)
我要被这个好用的memset气死了...... 真香 #include <cstring> #include <string> int main () { ]; memset( ...
- Hdu2612 Find a way 2017-01-18 14:52 59人阅读 评论(0) 收藏
Find a way Time Limit : 3000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Su ...
- HDU2612 -暑假集训-搜索进阶N
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82828#problem/N这两天总是因为一些小错误耽误时间,我希望自己可以细心点.珍惜 ...
随机推荐
- FunDA(6)- Reactive Streams:Play with Iteratees、Enumerator and Enumeratees
在上一节我们介绍了Iteratee.它的功能是消耗从一些数据源推送过来的数据元素,不同的数据消耗方式代表了不同功能的Iteratee.所谓的数据源就是我们这节要讨论的Enumerator.Enumer ...
- 编写 ES6 的 7 个实用技巧
无脑翻译走一波~ Hack #1 - 变量交换 使用数组解构交换变量的值 let a = 'world', b = 'hello' [a, b] = [b, a] console.log(a) // ...
- javascript 模块依赖管理的本质
模块模式定义 模块是'javascript'的一种设计模式,它为函数定义一个包装函数,并且该包装函数的返回值与模块的API保持一致: function createModule() { functio ...
- 【BZOJ1502】【NOI2005】月下柠檬树 simpson 积分
特别提醒:eps至少要5e-6 首先我们来研究下平行光对投影的影响. 一个二维的图形,若它与光屏平行,那么不论平行光与光屏的夹角为多少,所得图形与原图形全等的(只是位置会有影响) 通过这么一分析,我们 ...
- 【PaddlePaddle系列】报错解决方法合集 (不定时更新)
1.PaddlePaddle使用CPU时正常运行,但是使用GPU时却报出一堆错误信息,节选如下: paddle.fluid.core.EnforceNotMet: enforce allocating ...
- Grid++Report——打印功能
一.安装下载 http://www.rubylong.cn/Download.htm 二.添加引用 三.添加类 四.制作打印模板 1.新增报表节 新增明细网格 新增列→设置为自由格→调整大小 报表→设 ...
- if嵌套语句 shell脚本实例 测试是否闰年
在 if 语句里面,你可以使用另外一个 if 语句.只要你能逻辑管理 你就可以使用多层嵌套. 以下是一个测试闰年的例子: #!/bin/bash # This script will test if ...
- Android中的各种访问权限Permission含义
android.permission.EXPAND_STATUS_BAR 允许一个程序扩展收缩在状态栏,android开发网提示应该是一个类似Windows Mobile中的托盘程序 android. ...
- android listview实现点击某个item后使其显示在屏幕顶端
在该listview的点击事件中加入一下代码即可 listView.setSelectionFromTop(position, 0);
- Camtasia Studio的下载
不多说,直接上干货! 具体还没写 https://www.techsmith.com/video-editor.html 欢迎大家,加入我的微信公众号:大数据躺过的坑 人工智能躺过的坑 ...