萌新刚学OI,求助
查看原帖
萌新刚学OI,求助
55740
丧黑福造楼主2020/5/28 21:57

RTRT

#include <stdio.h>
int a[1505][1505];
bool v[1505][1505];
int c[100005];
int fx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int fy[8] = {1, 0, -1, 0, 1, -1, 1, -1};
int tmp;
int sum, ans, ans_max;
int n, m;
inline void dfs (int x, int y) {
	tmp ++;
	v[x][y] = 1;
	for (register int i = 0; i < 8; i ++) {
		int xx = x + fx[i];
		int yy = y + fy[i];
		if (xx < 1 || xx > n || yy < 1 || yy >m) continue;
		if (a[xx][yy] == '*' && !v[xx][yy])
			dfs (xx, yy);
	}
}
main() {
	scanf ("%d %d", &n, &m);
	for (register int i = 1; i <= n; i ++)
		for (register int j = 1; j <= n; j ++)
			scanf ("%c", &a[i][j]);
	for (register int i = 1; i <= n; i ++) {
		for (register int j = 1; j <= m; j ++) {
			if (a[i][j] == '*' && !v[i][j]) {
				tmp = 0;
				dfs (i, j);
				c[tmp] ++;
				sum = sum > tmp ? sum : tmp;
			}
		}
	}
	for (register int i = 1; i <= sum; i ++)
		if (c[i]) {
			ans ++;
			ans_max = ans_max > c[i] * i ? ans_max : c[i] * i;
		}
	printf ("%d %d\n", ans, ans_max);
	return 0;
} 

思路应该没有问题,但样例都没过qwq,求助大佬

(没时间自己调了明天要考试)

2020/5/28 21:57
加载中...