请问各位ACMdalao,我的程序为什么一直Runtime Error(ACCESS_VIOLATION) ,hdu2612,简单bfs

qq_32098651 2016-12-15 06:18:09
请问各位ACMdalao,我的程序为什么一直Runtime Error(ACCESS_VIOLATION) ,

hdu2612,简单bfs

题目如下
Find a way

Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 11419 Accepted Submission(s): 3741


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.


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


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 4
Y.#@
....
.#..
@..M
4 4
Y.#@
....
.#..
@#.M
5 5
Y..@.
.#...
.#...
@..M.
#...#


Sample Output
66
88
66


我的代码

#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>

using namespace std;

int n, m;
char map[225][225];
int Yi_times[225][225],Mer_times[225][225];
int Yi_bx, Yi_by, Mer_bx, Mer_by;
int KFCx[225], KFCy[225], numofKFC;
int totaltime[225];

void bfs(int bx,int by,int (*ptime)[225])
{
queue<int> s;
s.push(bx); s.push(by);

ptime[bx][by] = 1;
int tx, ty;
while (!s.empty())
{
tx = s.front(); s.pop();
ty = s.front(); s.pop();

for(int i=-1;i<=1;i++)
for (int j = -1; j <= 1; j++)
{
if (i != j&&i != -j)
{
int nx = tx + i;
int ny = ty + j;

if (nx >= 0 && ny >= 0 && nx < n&&ny < m&&map[nx][ny]!='#' && !ptime[nx][ny])
{
ptime[nx][ny] = ptime[tx][ty] + 1;
s.push(nx); s.push(ny);
}
}
}

}


}
int main()
{
while (scanf("%d %d", &n, &m) != EOF&&n&&m)
{
memset(Yi_times, 0, sizeof(Yi_times));
memset(Mer_times, 0, sizeof(Mer_times));
memset(totaltime, 0, sizeof(totaltime));
numofKFC = 0;

for(int i=0;i<n;i++)
for (int j = 0; j < m; j++)
{
cin >> map[i][j];

if (map[i][j] == 'Y')
{
Yi_bx = i;
Yi_by = j;
}
if (map[i][j] == 'M')
{
Mer_bx = i;
Mer_by = j;
}
if (map[i][j] == '@')
{

KFCx[numofKFC] = i;
KFCy[numofKFC] = j;
numofKFC++;
}
}

bfs(Yi_bx, Yi_by, Yi_times);
bfs(Mer_bx, Mer_by, Mer_times);

for (int i = 0; i < numofKFC; i++)
{
if (Yi_times[KFCx[i]][KFCy[i]] != 0 && Mer_times[KFCx[i]][KFCy[i]] != 0)
totaltime[i] = Yi_times[KFCx[i]][KFCy[i]] + Mer_times[KFCx[i]][KFCy[i]] - 2;
else
totaltime[i] = 0;
}



//cout << (*min_element(totaltime, totaltime + numofKFC)) * 11 << endl;
//sort(totaltime, totaltime + numofKFC);
int min = 9999;
for (int i = 0; i < numofKFC; i++)
{
if (totaltime[i]!=0&&min > totaltime[i])
min = totaltime[i];
}
cout << min * 11 << endl << endl;
/*for (int i = 0; i < numofKFC; i++)
cout << totaltime[i] << endl;*/

}
}

...全文
121 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
FancyMouse 2016-12-16
  • 打赏
  • 举报
回复
KFC可以不止225个……

65,186

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧