HDU
来源:互联网 发布:三国无双Mac版 编辑:程序博客网 时间:2024/06/06 00:43
题目链接: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): 16192 Accepted Submission(s): 5198
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.
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
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
Author
yifenfei
Source
奋斗的年代
Recommend
yifenfei
已Y和M为起点 对图广搜 book标记步数
将所有的kfc点存在一个容器中 然后依次判断最小值(注意这里可能存在有的kfc不能到达 这个地方栽跟头了 记得多加这个判断就行)
#include <iostream>#include <queue>#include <stdio.h>#include <stdlib.h>#include <stack>#include <limits.h>#include <string>#include <string.h>#include <vector>#include <set>#include <map>#include <algorithm>#include <math.h>using namespace std;char mmap[222][222];int bookm[222][222];int booky[222][222];struct xjy{ int x; int y;};xjy bem,bey;int n,m,k;queue <xjy > q,qq;int dir[4][2]={1,0,-1,0,0,1,0,-1};void bfsm(){ while(!q.empty()) q.pop(); for(int i=0;i<=201;i++) for(int j=0;j<=201;j++) { bookm[i][j]=INT_MAX; } bookm[bem.x][bem.y]=0; xjy mid; q.push(bem); while(!q.empty()) { mid=q.front(); q.pop(); xjy midmid; for(int i=0;i<4;i++) { midmid.x=mid.x+dir[i][0]; midmid.y=mid.y+dir[i][1]; if(mmap[midmid.x][midmid.y]!='#'&&mmap[midmid.x][midmid.y]!='M'&&bookm[midmid.x][midmid.y]>(bookm[mid.x][mid.y]+1)) { bookm[midmid.x][midmid.y]=bookm[mid.x][mid.y]+1; q.push(midmid); } } }}void bfsy(){ while(!q.empty()) q.pop(); for(int i=0;i<=201;i++) for(int j=0;j<=201;j++) { booky[i][j]=INT_MAX; } booky[bey.x][bey.y]=0; xjy mid; q.push(bey); while(!q.empty()) { mid=q.front(); q.pop(); xjy midmid; for(int i=0;i<4;i++) { midmid.x=mid.x+dir[i][0]; midmid.y=mid.y+dir[i][1]; if(mmap[midmid.x][midmid.y]!='#'&&mmap[midmid.x][midmid.y]!='Y'&&booky[midmid.x][midmid.y]>(booky[mid.x][mid.y]+1)) { booky[midmid.x][midmid.y]=booky[mid.x][mid.y]+1; q.push(midmid); } } }}int main(){ while(~scanf("%d%d",&n,&m)) { while(!qq.empty()) qq.pop(); memset(mmap,'#',sizeof(mmap)); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) { scanf(" %c",&mmap[i][j]); if(mmap[i][j]=='@') { xjy mid; mid.x=i;mid.y=j; qq.push(mid); } else if(mmap[i][j]=='Y') { bey.x=i;bey.y=j; } else if(mmap[i][j]=='M') { bem.x=i;bem.y=j; } } bfsm(); bfsy(); int ans=INT_MAX; while(!qq.empty()) { xjy mid; mid=qq.front(); qq.pop(); int aans=INT_MAX; if(booky[mid.x][mid.y]!=INT_MAX&&bookm[mid.x][mid.y]!=INT_MAX) { aans=min(bookm[mid.x][mid.y]+booky[mid.x][mid.y],aans); ans=min(aans,ans); } } cout << ans*11 << endl; }}
阅读全文
0 0
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- hdu
- hdu
- HDU
- hdu 6052 To my boyfriend 暴力枚举+容斥去重
- STL学习之十五:STL综合案例--演讲比赛
- 题目1047:素数判定
- js获取当前时间的年月日时分秒
- HDU-1394(线段树|归并排序)
- HDU
- 修改Metasploit安卓Payload源码以实现持久化访问
- springMVC学习总结
- 判断Cpu的字节序
- JVM调优总结(一):概念
- STL总结——set
- 由结构体对齐而引发的思考(二)类对象内存模型
- ffmpeg之demux 解复用
- JavaScript实战-DOM操作之奇偶变色表格2