⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1033.c

📁 平时acm训练时ac的源代码
💻 C
字号:
#include <stdio.h>
#include <string.h>

char matrix[35][35];
int m[35][35];
int N;
char ch;

void INIT(int x, int y)
{
	m[x][y] = 1;
	if (x + 1 <= N && matrix[x+1][y] != '#' && m[x+1][y] != 1) INIT(x+1, y);
	if (x - 1 >= 1 && matrix[x-1][y] != '#' && m[x-1][y] != 1) INIT(x-1, y);
	if (y + 1 <= N && matrix[x][y+1] != '#' && m[x][y+1] != 1) INIT(x, y+1);
	if (y - 1 >= 1 && matrix[x][y-1] != '#' && m[x][y-1] != 1) INIT(x, y-1);

}

main()
{
	int i, j, total;

    	scanf("%d", &N);
	ch = getchar();
	for (i = 1; i <= N; ++i) {
		for (j = 1; j <= N; ++j)
            matrix[i][j] = getchar();
		ch = getchar();
	}

	INIT(1, 1);
	INIT(N, N);

	total = 0;
	for (i = 1; i <= N; ++i ) {
		for (j = 1; j <= N; ++j) {
			if (m[i][j] == 1) {
				if (m[i+1][j] == 0 || i+1 > N) total++;
				if (m[i-1][j] == 0 || i-1 < 1) total++;
				if (m[i][j+1] == 0 || j+1 > N) total++;
				if (m[i][j-1] == 0 || j-1 < 1) total++;
			} 
		}
	}
		
	total -= 4;
	printf("%d\n", total*9);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -