HDU Find a way
来源:互联网 发布:everything微课软件 编辑:程序博客网 时间:2024/05/18 20:37
Find a way
Time Limit : 3000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 137 Accepted Submission(s) : 41
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
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
4 4Y.#@.....#..@..M4 4Y.#@.....#..@#.M5 5Y..@..#....#...@..M.#...#
Sample Output
668866
#include<iostream>#include<algorithm>#include<string.h>#include<queue>#include<cstdio>int n,m;char a[201][201],d[4][2]= {{1,0},{-1,0},{0,1},{0,-1}};using namespace std;struct node{ int x,y,step;};int main(){ while(scanf("%d%d",&n,&m)!=EOF) { bool b[201][201]; int c1[201][201],c2[201][201]; memset(b,0,sizeof(b)); for(int i=0; i<n; i++) scanf("%s",&a[i]); int x1,y1,x2,y2; for(int i=0; i<n; i++) for(int j=0; j<m; j++) { if(a[i][j]=='Y') x1=i,y1=j,a[i][j]=='.'; if(a[i][j]=='M') x2=i,y2=j,a[i][j]=='.'; } for(int i=0; i<n; i++) for(int j=0; j<m; j++) c1[i][j]=1000000,c2[i][j]=1000000; queue<node> P; node dd; dd.x=x1,dd.y=y1,dd.step=0; b[x1][y1]=1; P.push(dd); while(!P.empty()) { node dc=P.front(); P.pop(); for(int i=0; i<4; i++) { int xx=dc.x+d[i][0],yy=dc.y+d[i][1],step2=dc.step+11; if(xx>=0&&xx<n&&yy>=0&&yy<m) { if(a[xx][yy]=='@'&&b[xx][yy]==0) { c1[xx][yy]=step2,b[xx][yy]=1; node df; df.x=xx,df.y=yy,df.step=step2; P.push(df); } if(a[xx][yy]=='.'&&b[xx][yy]==0) { node dr; dr.x=xx,dr.y=yy,dr.step=step2; P.push(dr); b[xx][yy]=1; } } } } dd.x=x2,dd.y=y2,dd.step=0; P.push(dd); memset(b,0,sizeof(b)); b[x2][y2]=1; while(!P.empty()) { node dc=P.front(); P.pop(); for(int i=0; i<4; i++) { int xx=dc.x+d[i][0],yy=dc.y+d[i][1],step2=dc.step+11; if(xx>=0&&xx<n&&yy>=0&&yy<m) { if(a[xx][yy]=='@'&&b[xx][yy]==0) { c2[xx][yy]=step2,b[xx][yy]=1; node df; df.x=xx,df.y=yy,df.step=step2; P.push(df); } if(a[xx][yy]=='.'&&b[xx][yy]==0) { node dr; dr.x=xx,dr.y=yy,dr.step=step2; P.push(dr); b[xx][yy]=1; } } } } int min1=999999; for(int i=0; i<n; i++) for(int j=0; j<m; j++) { if(a[i][j]=='@') { if(c1[i][j]+c2[i][j]<min1) min1=c1[i][j]+c2[i][j]; } } printf("%d\n",min1); } return 0;}
- hdu Find a way
- hdu Find a way
- HDU:Find a way
- Find a way HDU
- Find a way HDU
- Find a way HDU
- Find a way HDU
- HDU Find a way
- HDU 2612 Find a way
- HDU-2612-Find a way
- hdu 2612 Find a way
- HDU 2612 Find a way
- hdu 2612 Find a way
- HDU 2612 Find a way
- HDU 2612 Find A Way
- hdu 2612 Find a way
- HDU-2612-Find a way
- HDU 2612 Find a way
- 2017-12-20
- java8中双冒号的使用
- 有关信道的几个基本概念
- getBoundingClientRect() 与 offset
- No repository found containing 问题的处理
- HDU Find a way
- bzoj 4811: [Ynoi2017]由乃的OJ
- Kafka文件存储机制那些事
- Shell 自动化编译打包
- Android音视频录制(4)——变速录制
- 探索者TSSD结构CAD3.0(包含单机版和网络版)带破解
- UE4如何上传文件
- 分治---循环赛日程表
- Android第三方库:Glide源码解析