1 条题解
-
0
由题意可得,最终校园的边长是 。取极限数据时,,所以可以按照题意,暴力构建校园,最后用 DFS 求连通块数目即可。
#include<bits/stdc++.h> using namespace std; #define endl '\n' const int N = 2500; int a[N][N], nw[N][N], res[N][N]; int siz; bool vis[N][N]; int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; void dfs(int x,int y) { vis[x][y] = 1; for (int i = 0; i < 4; i++) { int xx = x + dx[i], yy = y + dy[i]; if (xx >= 1 && xx <= siz && yy >= 1 && yy <= siz && res[xx][yy] && !vis[xx][yy]) dfs(xx, yy); } } int main() { freopen("exp.in","r",stdin); freopen("exp.out","w",stdout); ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); int n, k, c; cin >> n >> k >> c; for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) cin >> a[i][j]; siz = 1, res[1][1] = 1; while(k--) { for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) // 枚举当前是被复制的第几块 { for(int x = 1; x <= siz; x++) for(int y = 1; y <= siz; y++) // 枚举这一块中的所有点 { if(a[i][j] == 1) nw[(i - 1) * siz + x][(j - 1) * siz + y] = res[x][y]; else nw[(i - 1) * siz + x][(j - 1) * siz + y] = 0; } } siz *= n; for(int i = 1; i <= siz; i++) for(int j = 1; j <= siz; j++) res[i][j] = nw[i][j]; } int ans = 0; for(int i = 1; i <= siz; i++) for(int j = 1; j <= siz; j++) if(res[i][j] && !vis[i][j]) { ans++; dfs(i, j); } cout << ans; return 0; }
- 1
信息
- ID
- 511
- 时间
- 500ms
- 内存
- 512MiB
- 难度
- 9
- 标签
- (无)
- 递交数
- 38
- 已通过
- 4
- 上传者