社区讨论

求助

P1596[USACO10OCT] Lake Counting S参与者 1已保存回复 0

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
0 条
当前快照
1 份
快照标识符
@lxsksvz7
此快照首次捕获于
2024/06/24 14:07
2 年前
此快照最后确认于
2024/06/24 18:25
2 年前
查看原帖
CPP
#undef wrap
#undef print	
#include<bits/stdc++.h>
using namespace std;
#define wrap() printf("\n")
typedef long long int ll;
typedef int si;
typedef unsigned int ui;
typedef unsigned long long ull;
//typedef unsigned __int128 uint128;	
const int E = 1e6*4+10;
const int S = 1e7+10;
const int U = 1<<30;
const int T = 1e4*2+10;
const int F = 65540;//F = 65535 + 5
const int Q = 3010;
const long long Y = 1LL<<60LL;	
const int maxp = 1e5 + 10;
void print(int t){printf("%d",t);}
void print(long long t){printf("%lld",t);}
void print(string t){cout << t;}
void print(int t,bool b,bool c) 
{
	printf("%d",t);
	if(b) wrap();
	if(c) print(" ");
}
void print(long long t,bool b,bool c) 
{
	printf("%lld",t);
	if(b) wrap();
	if(c) print(" ");
}
void print(string t,bool b,bool c) 
{
	cout << t;
	if(b) wrap();	
	if(c) print(" ");
}
ll gcd(ll a,ll b)
{
	if(b==0)return a;
	return gcd(b,a%b);
}
ll lcm(ll a, ll b)
{
	long long temp = a * b;
	temp = temp / gcd(a, b);
	return temp;
}
si gcd(si a,si b)
{
	if(b==0)return a;
	return gcd(b,a%b);
}
si lcm(si a, si b)
{
	si temp = a * b;
	temp = temp / gcd(a, b);
	return temp;
}
ll gcd(si a,ll b)
{
	if(b==0)return a;
	return gcd(b,a%b);
}
ll lcm(si a, ll b)
{
	long long temp = a * b;
	temp = temp / gcd(a, b);
	return temp;
}
ll gcd(ll a,si b)
{
	if(b==0)return a;
	return gcd(b,a%b);
}
ll lcm(ll a, si b)
{
	long long temp = a * b;
	temp = temp / gcd(a, b);
	return temp;
}

const int D[8][2] = 
{
	{1,0},
	{-1,0},
	{0,1},
	{0,-1},
	{-1,-1},
	{1,1},
	{-1,1},
	{1,-1}
};
int n,m,a[1001][1001],ans;
char s[E];
bool b[1001][1001];

inline void dfs(int x,int y)
{
	b[x][y] = true;
	for(int l=0;l<8;l++)
	{
		int xx = x+D[l][0],yy = y+D[l][1];
		if(xx < 0 || xx > n || yy < 0 || yy > n) continue;
		if(a[xx][yy] == 0 && !b[xx][yy]) 
		{
			b[xx][yy] = true;
			dfs(xx,yy);
		}
	}
}

int main()
{
	cin >> n >> m;
	for(int i=1;i<=n;i++)
	{
		scanf("%s",s+1);
		for(int j=1;j<=m;j++) 
		{
			if(s[j] == 'W') a[i][j] = 0;
			else a[i][j] = 1;
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(a[i][j] == 0 && !b[i][j])
			{
				dfs(i,j);
				ans++;
			}
		}
	}
	cout << ans;
}

回复

0 条回复,欢迎继续交流。

正在加载回复...