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 |
谁能帮我看看为什么WA?交了很多遍了一直这样#include<stdio.h> #define INF 1<<20 #define Enqueue( r , c ) q[front][0] = r , q[front][1] = c , front++ #define Dequeue( r , c ) r = q[rear][0] , c = q[rear][1] , rear++ int map[512][512] ; int flag[512][512] ; int R , C ; int dr[] = { -1 , 0 , 1 , 0 } ; int dc[] = { 0 , 1 , 0 , -1 } ; int q[512 *512][2] ; void BFS( int r , int c ) { int rr , cc , i , front , rear ; front = rear = 0 ; Enqueue( r , c ) ; while( rear < front) { Dequeue( r , c ) ; for( i = 0 ; i <= 3 ; i++ ) { rr = r + dr[i] ; cc = c + dc[i] ; if( rr >= 0 && rr < R && cc >= 0 && cc < C && map[rr][cc] + flag[r][c] < flag[rr][cc] ) { flag[rr][cc] = map[rr][cc] + flag[r][c] ; Enqueue( rr , cc ) ; } } } } int main() { int i , k , tr , tc , sr , sc ; char s[512] ; while( 1 ) { scanf("%d%d" , &R , &C ) ; if( R == 0 && C == 0 ) { return 0 ; } for( i = 0 ; i < R ; i++ ) { scanf("%s" , s ) ; for( k = 0 ; k < C ; k++ ) { flag[i][k] = INF ; if( s[k] == 'Y' ) { sr = i ; sc = k ; flag[i][k] = 0 ; } else if( s[k] == 'T' ) { map[i][k] = 1 ; tr = i ; tc = k ; } else if( s[k] == 'B' ) { map[i][k] = 2 ; } else if( s[k] == 'E') { map[i][k] = 1 ; } else { map[i][k] = INF ; } } } BFS( sr , sc ) ; printf("%d\n" , flag[tr][tc] ) ; } return 0 ; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator