谁知道这什么东西
查看原帖
谁知道这什么东西
1466243
yjc19143397楼主2024/9/30 21:05
#include<bits/stdc++.h>
using namespace std;

const int N=7e3+200;
const int dx[]= {0,0,1,-1};
const int dy[]= {1,-1,0,0};
bool dict[N][N]={0},vis[N][N]={0};
int n,top,flag;
//int st[N][2];
char m;

struct node {
	int x,y;

} st[N];


void dfs(node a) {
	st[++top]=a;
	while(top!=0) {
		int x=st[top].x,y=st[top--].y;
		vis[x][y]=1;
		if(dict[x+1][y]&&dict[x-1][y]&&dict[x][y+1]&&dict[x][y-1])flag=0;
		for(int i=0; i<4; ++i) {
			int nx=x+dx[i],ny=y+dy[i];
			if((!vis[nx][ny])&&dict[nx][ny]){
				st[++top]=node {nx,ny};
			}
		}
	}
	return ;
}

int main() {
	cin>>n;
	for(int i=0; i<n; ++i) {
		for(int j=0; j<n; ++j) {
			cin>>m;
			if(m=='#')dict[i][j]=1;
		}
	}
	int ans=0;
	for(int i=0; i<n; ++i) {
		for(int j=0; j<n; ++j) {
			if(dict[i][j]&&!vis[i][j]) {
				flag=1;
				dfs(node {i,j});
				ans+=flag;

			}
		}
	}

	cout<<ans;
	return 0;
}

84分。。。

蒟蒻一枚 求佬大指导

2024/9/30 21:05
加载中...