7 条题解
-
0
#include<bits/stdc++.h> using namespace std; const int N = 50 + 10; int n , m , a[N][N] , ans , maxx,dx[] = {0, -1 , 0 , 1},dy[] = {-1, 0 , 1 , 0}; bool v[N][N]; struct node { int x , y; }; queue<node> q; void bfs(int x , int y) { q.push((node){x , y}); int cnt = 1; v[x][y] = 1; while(!q.empty()) { node top = q.front(); q.pop(); for(int i = 0 ; i <= 3; i++) { int xx = top.x + dx[i]; int yy = top.y + dy[i]; if( xx >= 1 && xx <= n && yy >= 1 && yy <= m && v[xx][yy] == 0 && (a[top.x][top.y] & (1 << i)) == 0 ) { cnt++; v[xx][yy] = 1; q.push((node){xx , yy}); } } } maxx = max(maxx , cnt); } int main() { cin >> n >> m; for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) cin >> a[i][j]; for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) { if(v[i][j] == 0) { ans++; bfs(i , j); } } cout << ans << endl << maxx; return 0; }
信息
- ID
- 1344
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 4
- 标签
- 递交数
- 127
- 已通过
- 56
- 上传者