本文共 2155 字,大约阅读时间需要 7 分钟。
Find a way
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 10758 Accepted Submission(s): 3538 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.
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
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.
4 4Y.#@.....#..@..M4 4Y.#@.....#..@#.M5 5Y..@..#....#...@..M.#...#
yifenfei | We have carefully selected several similar problems for you:
#include #include #include #include #include #define inf 0x6ffffffusing namespace std;int vis[250][250];char map[250][250];int dx[]={ 1,-1,0,0};int dy[]={ 0,0,1,-1};int s1,s2;int s3,s4;int flag[250][250];//用于记录步数int flag2[250][250];int n,m;typedef pair p;void bfs(int sx,int sy,int a[250][250]){ queue que; que.push(p(sx,sy)); vis[sx][sy]=1; while(!que.empty()) { p now=que.front(); que.pop(); int ex=now.first; int ey=now.second; for(int i=0;i<4;i++) { int x=ex+dx[i]; int y=ey+dy[i]; //cout<
<<" "< < =n||x<0||y>=m||y<0||vis[x][y]||map[x][y]=='#') continue; if(x y&&x>=0&&y>=0&&map[x][y]!='#'&&!vis[x][y]) { vis[x][y]=1; a[x][y]=a[ex][ey]+1; } que.push(p(x,y)); } }}int main(){ while(~scanf("%d%d",&n,&m)) { for(int i=0;i
转载地址:http://fafci.baihongyu.com/