Atcoder beginner contest 129D Lamp

https://atcoder.jp/contests/abc129/tasks/abc129_d
题意:在一个由“.”和“#”构成的图中,找一个点使它在上下方向和左右方向能直接到达的“.”最多(“#”不能穿过)。
思路:先预处理出每一个点左右和上下方向能到的数量,在暴力枚举每一个点,取最大值。难度貌似不大。

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define ll long long
#define pii pair
#define mp make_pair
#define fi first
#define se second
#define inf 0x7fffffff
using namespace std;
string s[2010];
int a[2010][2010],b[2010][2010];
int numa[2010*2010],numb[2010*2010];
int main()
{
	int i,j,k,n,m,x,y,h=0;
	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++)
	{
		cin>>s[i];
	}
	for(i=0;i<n;i++)
	{
		x=0;
		for(j=0;j<m;j++)
		{
			if(s[i][j]=='#')
			{
				if(x>0)
				{
					numa[h]=x;
					x=0;
					h++;
				}
			}
			else
			{
				a[i][j]=h;
				x++;
			}
		}
		if(x>0)
		{
			numa[h]=x;
			h++;
		}
	}
	h=0;
	for(i=0;i<m;i++)
	{
		x=0;
		for(j=0;j<n;j++)
		{
			if(s[j][i]=='#')
			{
				if(x>0)
				{
					numb[h]=x;
					x=0;
					h++;
				}
			}
			else
			{
				b[j][i]=h;
				x++;
			}
		}
		if(x>0)
		{
			numb[h]=x;
			h++;
		}
	}
	int ma=0;
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		{
			ma=max(ma,numa[a[i][j]]+numb[b[i][j]]-1);
		}
	}
	printf("%d",ma);
	return 0;
}

你可能感兴趣的:(atcoder,atcoder)