玄学错误,求大佬看过来!!!!!!!!!

P2802 回家

都是关于k的类型,中间也有测试其他的部分,但是没有产生影响,问题就集中在k上面,莫名其妙的。
by 段落 @ 2023-07-27 16:52:00


_好神奇_ bool类型不是只有0/1么??? ~~bool类型有3!!!~~
by kevin0313 @ 2023-07-27 17:21:15


~~直接不要 k~~ ```cpp #include<bits/stdc++.h> using namespace std; int n,m,a[10][10],b[10][10],t; int c_x,c_y,f_x,f_y; int dx[] = {0,0,1,-1}; int dy[] = {1,-1,0,0}; queue<int>q; void bfs(int x,int y){ q.push(x); q.push(y); q.push(0); while(q.size()){ x = q.front(); q.pop(); y = q.front(); q.pop(); t = q.front(); q.pop(); if(a[x][y] == 4) b[x][y] = 6; if(x == f_x && y == f_y){ cout << t; exit(0); } for(int i = 0;i < 4;i ++){ int xx = x + dx[i]; int yy = y + dy[i]; if(x < 1 || x > n || y < 1 || y > m || a[x][y] == 0) ;else if(b[x][y] - 1 > b[xx][yy]){ b[xx][yy] = b[x][y] - 1; q.push(xx); q.push(yy); q.push(t + 1); } } } } int main(){ cin >> n >> m; for(int i = 1;i <= n;i ++){ for(int j = 1;j <= m;j ++){ cin >> a[i][j]; if(a[i][j] == 3){ f_x = i; f_y = j; } if(a[i][j] == 2){ c_x = i; c_y = j; } } } b[c_x][c_y] = 6; bfs(c_x,c_y); cout << -1; return 0; } ```
by A1438329629 @ 2023-07-27 17:44:06


@[A1438329629](/user/583276) 谢谢,这样是可以的,主要还是想清楚我的写法结果为什么会各不相同
by 段落 @ 2023-07-27 21:02:24


|