2pow10 @ 2023-10-07 12:38:59
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 10100;
int n,num;
int pan[N*N];
char shu='1';
char g[N][N];
int dx[4]= {-1,0,1,0};
int dy[4]= {0,-1,0,1};
void check(int a,int b) {
g[a][b] = shu;
for(int i=0; i<4; i++) {
int x=a+dx[i];
int y=b+dy[i];
if (x < 1 || x > n || y < 1 || y > n) continue;
if(g[x][y]=='#') check(x,y);
}
}
signed main() {
/* ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);*/
cin >> n;
for(int i=1; i<=n; i++) {
for(int j=1; j<=n; j++) {
cin >> g[i][j];
}
}
for(int i=1; i<=n; i++) {
for(int j=1; j<=n; j++) {
if(g[i][j]=='#') {
check(i,j);
shu++;
}
}
}
for(int i=1; i<=n; i++) {
for(int j=1; j<=n; j++) {
if(g[i][j]!='.'&&g[i][j]!='@') {
if(g[i][j+1]=='.'||g[i][j-1]=='.'||g[i+1][j]=='.'||g[i-1][j]=='.') g[i][j] = '@';
}
}
}
for(int i=1; i<=n; i++) {
for(int j=1; j<=n; j++) {
if(g[i][j]!='.' && g[i][j]!='@' && !pan[ g[i][j]-'0' ]) {
num++;
pan[g[i][j]-'0'] = 1;
}
}
}
cout << shu-'0'-num-1;
return 0;
}
by TallBanana @ 2023-10-07 12:54:08
你这数组不爆空间?
by 2pow10 @ 2023-10-07 22:13:09
因为爆了所以不知道怎么改@Tallbanana
by TallBanana @ 2023-10-08 12:47:12
@2pow10 N不能少一个0吗
by 2pow10 @ 2023-10-08 13:16:12
少了也会RE@TallBanana
by kk22syx @ 2024-03-15 22:33:19
请问最后一个点re解决了吗