Initial commit

This commit is contained in:
2025-03-14 22:39:32 +08:00
commit 7b1e0f329e
38 changed files with 1153 additions and 0 deletions

59
test99-3-5.cpp Normal file
View File

@@ -0,0 +1,59 @@
// lanqiao178 全球变暖
#include<bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
char mp[N][N];
int n, scc, col[N][N];
bool vis[N*N];
// 移动向量
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
void dfs(int x, int y){
col[x][y] = scc;
for(int i = 0; i < 4; i++){
int nx = x + dx[i], ny = y + dy[i];
if( col[nx][ny] || mp[nx][ny] == '.') continue; // 不需要判断nx, ny是否在地图里面因为地图边缘都是海洋
dfs(nx ,ny);
}
}
int main(){
ios::sync_with_stdio, cin.tie(0), cout.tie(0);
cin >> n;
for(int i = 1; i <= n; i++) cin >> mp[i] + 1;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
if(col[i][j] || mp[i][j] == '.') continue;
scc++; // scc表示当前颜色编号
dfs(i, j);
}
}
int ans = 0;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
if(mp[i][j] == '.') continue;
bool tag = true;
for(int k = 0; k < 4; k++){
int x = i + dx[k], y = j + dy[k];
if(mp[x][y] == '.') tag = false;
}
if(tag){
if(!vis[col[i][j]]) ans++;
vis[col[i][j]] = true;
}
}
}
cout << scc - ans << '\n';
return 0;
}
/* test samples
7
.......
.##....
.##....
....##.
..####.
...###.
.......
*/