求解,为什么只有60分QAQ...

P1849 [USACO12MAR] Tractor S

解决了qwq... 要多开一列QAQ... 在判断的时候判断xx>1001||yy>1001就好了QAQ..(有大佬给解释下吗) AC代码: ```cpp #include <cstdio> #include <cstring> #include <algorithm> #include <iostream> #include <queue> const int N = 1020; int dx[] = { 0 , 0 , 1 , -1 }; int dy[] = { 1 , -1 , 0 , 0 }; int n , sx , sy; int mp[N][N] , dis[N][N]; bool inque[N][N]; struct Node { int x; int y; Node ( int x , int y ) : x ( x ) , y ( y ) {} Node() {} }; std :: queue < Node > qu; inline int read () { int s = 0 , w = 1; char ch = getchar (); while ( ch > '9' || ch < '0' ) { if ( ch == '-' ) w = -1; ch = getchar ();} while ( ch >= '0' && ch <= '9' ) { s = s * 10 + ch - '0'; ch = getchar ();} return s * w; } void Spfa ( int x , int y ) { memset ( dis , 0x3f3f3f3f , sizeof ( dis ) ); inque[x][y] = 1; dis[x][y] = 0; qu.push ( Node ( x , y ) ); while ( !qu.empty () ) { Node j = qu.front (); inque[j.x][j.y] = 0; qu.pop (); for ( int i = 0 ; i < 4 ; i++ ) { int xx = j.x + dx[i]; int yy = j.y + dy[i]; if ( xx > 1001 || yy > 1001 || xx < 0 || yy < 0 ) continue; if ( dis[xx][yy] > dis[j.x][j.y] + mp[xx][yy] ) { dis[xx][yy] = dis[j.x][j.y] + mp[xx][yy]; if ( !inque[xx][yy] ) { inque[xx][yy] = 1; qu.push ( Node ( xx , yy ) ); } } } } return; } int main ( void ) { //freopen ( "1.txt" , "r" , stdin ); n = read () , sx = read () , sy = read (); for ( int i = 1 ; i <= n ; i++ ) { int x = read () , y = read (); mp[x][y] = 1; } Spfa ( sx , sy ); printf ( "%d\n" , dis[0][0] ); return 0; } ```
by 兮水XiShui丶 @ 2018-09-26 20:26:08


@[Kirito_Rivaille](/space/show?uid=54047) 解释:虽然干草只能在1~1000范围内存在,但是拖拉机可以开到1001去
by 肖恩Sean @ 2019-03-19 19:13:07


|