有时候挺无助的,抄的b站上代码却编译不出来

P1162 填涂颜色

建议查看编译信息/qd ```b[i][j]=1``` 这行没加分号。
by MC小萌新 @ 2024-03-07 22:56:32


@[MC小萌新](/user/183954) 能帮忙看看为什么只过了两个吗 ```cpp #include<bits/stdc++.h> using namespace std; int Map[32][32]; queue<int> nowx; queue<int> nowy; int dx[4] = {-1, 1, 0, 0}; int dy[4] = {0, 0, -1, 1}; int vis[32][32]; int main() { int n; scanf("%d", &n); for(int i = 1; i <= n; i++) { for(int j = 1; j <= n; j++) { scanf("%d", &Map[i][j]); } } for(int i = 1; i <= n; i++) { for(int j = 1; j <= n; j++) { if(Map[i][j] == 0) Map[i][j] = 2; } } for(int i = 1; i <= n; i++) if(Map[1][i] == 2)Map[1][i] = 0; for(int i = 1; i <= n; i++) if(Map[i][1] == 2)Map[i][1] = 0; for(int i = 1; i <= n; i++) if(Map[i][n] == 2)Map[i][n] = 0; for(int i = 1; i <= n; i++) if(Map[n][i] == 2)Map[n][i] = 0; vis[1][1] = 1; nowx.push(1); nowy.push(1); while(!nowx.empty()) { for(int i = 0; i < 4; i++) { int nextx = nowx.front() + dx[i]; int nexty = nowy.front() + dy[i]; if(Map[nextx][nexty]!=1 && vis[nextx][nexty] == 0 && nextx >=0 && nextx <= n && nexty >=0 && nexty <= n) { vis[nextx][nexty] = 1; Map[nextx][nexty] = 0; nowx.push(nextx); nowy.push(nexty); } } nowx.pop(); nowy.pop(); } for(int i = 1; i <= n; i++) { for(int j = 1; j <= n; j++) printf("%d ",Map[i][j]); printf("\n"); } return 0; } ```
by huashuo @ 2024-04-02 23:20:06


|