1 solutions

  • 0
    @ 2022-1-19 21:16:08

    打卡

    #include <bits/stdc++.h>
    using namespace std;
    struct pre{
    	int x,y;
    };
    char w[1010][1010];
    int n,sum=0,x,y;
    int x1[5]={0,-1,0,1};
    int y2[5]={-1,0,1,0};
    int check(int x,int y){
    	return (x>=0&&x<n&&y>=0&&y<n&&w[x][y]=='.');
    }
    void bfs(){
    	queue<pre>q;
    	q.push((pre) {x,y});
    	while(!q.empty()){
    		int xx=q.front().x,yy=q.front().y;
    		q.pop();
    		for(int i=0;i<4;i++){
    		int xxx=xx+x1[i];
    		int yyy=yy+y2[i];
    		if(check(xxx,yyy)){
    			w[xxx][yyy]='*';
    			sum++;
    			q.push((pre){xxx,yyy});
    		} 
    	}
    	}
    	return ;
    }
    int main(){
    	cin>>n;
    	x=0,y=0;
    	for(int i=0;i<n;i++){
    		cin>>w[i];
    	}
    	w[0][0]='*';
    	bfs();
    	cout<<sum+1;
    	return 0;
    }
    • 1

    Information

    ID
    50
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    6
    Tags
    # Submissions
    53
    Accepted
    16
    Uploaded By