欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

【暴力】[NOI Online #3 入门组]观星

程序员文章站 2022-06-03 21:07:39
...

LinkLink

luogu P6566luogu\ P6566

DescriptionDescription

【暴力】[NOI Online #3 入门组]观星

SampleSample InputInput 11

5 7
*......
..**..*
.*...*.
...*...
....*..

SampleSample OutputOutput 11

3 4

SampleSample InputInput 22

10 10
**..**.**.
***....*..
*...**.**.
...*..*...
..........
**...**.*.
..*.*....*
..........
***..*.*..
.***..*...

SampleSample OutputOutput 22

4 12

HintHint

【暴力】[NOI Online #3 入门组]观星

TrainTrain ofof ThoughtThought

就直接暴力统计区块

CodeCode

#include<algorithm>
#include<iostream>
#include<cstdio>

using namespace std;

int ans, n, m, tt, op, sum;
int b[1505][1505], a[1505][1505], t[3000005], ansx[3000005];
int dx[8] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy[8] = {1, -1, 1, -1, 0, 1, -1, 0}; 

bool cmp(int i, int j)
{return i > j;}

bool legal(int x, int y)
{
	if (x > n || x < 1 || y > m || y < 1) return 0;
	return 1;
}//判断是否超出边界

int work(int x, int y)
{
	ans++;
	b[x][y] = 1;
	for (int i = 0; i < 8; ++i)
	{
		int xx = x + dx[i];
		int yy = y + dy[i];
		if (legal(xx, yy) && a[xx][yy] && !b[xx][yy]) 
		work(xx, yy);
	}
	return ans;
}

int main()
{
	char c;
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++i) {
	 	c = getchar();
		for (int j = 1; j <= m; ++j)
		{
			c = getchar();
			if (c == '*') a[i][j] = 1;
			else b[i][j] = 1;
		}
	}
	for (int i = 1; i <= n; ++i)
	for (int j = 1; j <= m; ++j)
		if (!b[i][j]) ans = 0, t[++tt] = work(i, j);//找出每一个星座
	sort(t + 1, t + tt + 1, cmp);
	for (int i = 1; i <= tt; ++i)
	{
		if (i == 1) sum = t[i];
 		else if (t[i] != t[i - 1]) ansx[++op] = sum, sum = t[i];
		else sum += t[i];
	}
	ansx[++op] = sum;
	sort(ansx + 1, ansx + op + 1);
	printf("%d %d", op, ansx[op]);
	return 0;
}
相关标签: 暴力