7 条题解

  • -1
    @ 2024-12-22 20:08:26
    #include<bits/stdc++.h>
    using namespace std;
    const int N = 1e5+10;
    int p[100][100],a[100][100],n,m,dx[]{0,-1,0,1},dy[]{-1,0,1,0};
    struct node
    {
    	int x,y;
    };
    int bfs(int x,int y){
    	queue<node> q;
    	q.push((node){x,y});
    	a[x][y]=1;
    	int sum=1;
    	while(!q.empty()){
    		node top=q.front(); 
    		q.pop();
    		for(int i = 0;i < 4;i++)
    		{
    			x = top.x+dx[i];
    			y = top.y+dy[i];
    			int r = p[top.x][top.y] & (1 << i);
    			if(r == 0 && !a[x][y])
    			{
    				a[x][y] = ++sum;
    				q.push((node){x , y});
    			} 
    		} 
    	}
    	return sum;
    }
    int main(){
    	cin>>n>>m;
    	for(int i = 0;i < n;i++){
    		for(int j = 0;j < m;j++){
    			cin>>p[i][j]; 
    		}
    	}
    	int num = 0,maxx = 0;
    	for(int i = 0;i < n;i++){
    		for(int j = 0;j < m;j++){
    			if(a[i][j] == 0){
    				num++;
    				maxx = max(maxx , bfs(i,j));
    			}
    		}
    	}
    	cout << num << endl;
    	cout << maxx << endl;
    	return 0;
    }
    
    

    信息

    ID
    1344
    时间
    1000ms
    内存
    256MiB
    难度
    4
    标签
    递交数
    127
    已通过
    56
    上传者