| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
此题数据挺弱的。4 4
....
A.C.
XXX.
B...
AB 2
BA 1
AC 3
XX 0
答案
1.50 3.00 3.00 3.00
0.00 4.50 0.00 3.00
0.00 0.00 0.00 3.00
0.00 3.00 3.00 3.00
此题数据挺弱的。
先用bfs找出最短路径。再用dfs找出有多少条路径。然后再用求load。
void bfs(ST_Node start, ST_Node end)
{
int i = 0;
int xx = 0, yy = 0;
int iIndex = 0;
char cEnd ;
ST_Node stTemp;
iBest = -1;
EnQ(start);
visit[start.y][start.x]= 1;
cEnd = map[end.y][end.x];
while(rear<front)
{
DeQ(&iIndex);
// printf("iIndex = %d, stQueue[iIndex].y = %d, stQueue[iIndex].x = %d, stQueue[iIndex].step = %d \n ", iIndex, stQueue[iIndex].y, stQueue[iIndex].x, stQueue[iIndex].step);
if(stQueue[iIndex].x == end.x && stQueue[iIndex].y == end.y )
{
iBest = stQueue[iIndex].step;
// printf("iBest = %d\n", iBest);
//
return ;
}
for(i = 0; i<4; i++)
{
yy = stQueue[iIndex].y + yMove[i];
xx = stQueue[iIndex].x + xMove[i];
// printf("yy = %d, xx = %d, stQueue[iIndex].y = %d, stQueue[iIndex].x = %d, visit[yy][xx] = %d\n", yy, xx, stQueue[iIndex].y, stQueue[iIndex].x, visit[yy][xx]);
if(xx>=0 && xx<XX && yy>=0 && yy<YY && 0 == visit[yy][xx] && (map[yy][xx] == '.' || map[yy][xx] == cEnd))
{
stTemp.x = xx;
stTemp.y = yy;
stTemp.step = stQueue[iIndex].step + 1;
visit[yy][xx] = 1;
EnQ(stTemp);
}
}
}
}
是正确的。
当我的判断条件。 if(xx>=0 && xx<XX && yy>=0 && yy<YY && 0 == visit[yy][xx] && (map[yy][xx] != 'X' )
也能对。数据太弱了。
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator