?不开O2wa#9#10,开了之后就过了
查看原帖
?不开O2wa#9#10,开了之后就过了
421517
棠棠棠棠棠এ楼主2021/10/14 07:13
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<queue>
using namespace std;
int xgo[4]={1,-1,0,0};
int ygo[4]={0,0,1,-1};
char map[1010][1010];
bool sf[1010][1010];
struct node1{
	int area,circumference;
}ice[1000010];
struct node{
	int x,y;
}now;
queue<node> q;
bool cmp(node1 a,node1 b)
{
	return (a.area==b.area?a.circumference<b.circumference:a.area>b.area);
}
int main()
{
	int n,t=0;
	cin>>n;
	for(int i=0;i<n;++i)
		scanf("%s",map[i]);
	for(int i=0;i<n;++i)
	{
		for(int j=0;j<n;++j)
		{
			if(map[i][j]=='#')
			{
				now.x=i;now.y=j;
				q.push(now);
				while(!q.empty())
				{
					now=q.front();
					++ice[t].area;
					map[now.x][now.y]='@';
					for(int k=0;k<4;++k)
					{
						now.x+=xgo[k];
						now.y+=ygo[k];
						if(now.x>=0&&now.x<n&&now.y>=0&&now.y<n&&!sf[now.x][now.y])
						{
							if(map[now.x][now.y]=='#') q.push(now);
							sf[now.x][now.y]=true;
						}
						if(map[now.x][now.y]!='@'&&map[now.x][now.y]!='#') ++ice[t].circumference;
						now.x-=xgo[k];
						now.y-=ygo[k];
					}
					q.pop();
				}
				++t;
			}
		}
	}
	sort(ice,ice+t,cmp);
	cout<<ice[0].area<<" "<<ice[0].circumference;
	return 0;
}
2021/10/14 07:13
加载中...