84分,WA一个

P1162 填涂颜色

underline__jian @ 2021-07-18 12:12:19

虽然有WA的,但是测评机的输入样例符合题目要求

#include<bits/stdc++.h>
using namespace std;
struct place{
    int x;
    int y;
}Place;
const int M=31;   
int map1[M][M]={0};
int visited[M][M];
int dx[4]={1,-1,0,0};
int dy[4]={0,0,-1,1};
int m,n,a,b,c;
queue<place>q;     
void bfs(int x,int y){
    visited[x][y]=1;   
    Place.x=x;
    Place.y=y;
    q.push(Place);   
    while(!q.empty()){
        struct place A=q.front(); 
        q.pop();
        int zx,zy;
        for(int i=0;i<4;i++){
            zx=A.x+dx[i];
            zy=A.y+dy[i];
            if(zx<0||zx>n+1||zy<0||zy>n+1||visited[zx][zy]==1)
                continue;
            else{
                    visited[zx][zy]=1;
                    struct place B;                 
                        B.x=zx;
                        B.y=zy;
                        q.push(B); 
            }
        }
    }
}
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            cin>>map1[i][j];
            if(map1[i][j]==0)  
                visited[i][j]=0;
            else 
                visited[i][j]=1;
        }
    }
    bfs(0,0);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(!visited[i][j]) cout<<"2"<<" ";    
            else cout<<map1[i][j]<<" ";;
        }
        cout<<endl;
    } 
    return 0;
}

错误地址


by Sliarae @ 2021-07-18 12:13:04

前排


by Sliarae @ 2021-07-18 13:47:09

@include 帮你跑了一下

5组数据:

30
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0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 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

你的代码好像只会输出1


by Sliarae @ 2021-07-18 13:51:18

@include 数组开小了

const int M=31;

应改为

const int M=32;

这样可以AC

AC记录


by underline__jian @ 2021-07-18 16:13:00

@十里是萌新啊

好的

欧克欧克


by Sliarae @ 2021-07-18 18:18:33

@include 还符合题目要求。。。


|