7 条题解
-
1
#include <stdio.h> #include <queue> #include <stack> #include <algorithm> #include <iostream> #include <math.h> #include <string.h> #include <vector> #define LL long long const int INF = 0x3f3f3f3f; const int N = 50+10; using namespace std; int n , m , a[N][N] , ans , maxx; bool v[N][N]; int dx[] = {0, -1 , 0 , 1};//西北东南 int dy[] = {-1, 0 , 1 , 0}; 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]; //(a[top.x][top.y] & (1 << i)) == 0 判断是否有墙 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
- 标签
- 递交数
- 128
- 已通过
- 56
- 上传者