洛谷P1789 【Mc生存】插火把

洛谷P1789 【Mc生存】插火把_第1张图片

#define  _CRT_SECURE_NO_WARNINGS 1

//用c++的头写c要不然会有一个RE
#include 
using namespace std;

int n, m, k, x, y, ans, a[101][101]; //数组不需要开那么大101足够

int main()
{
	scanf("%d %d %d", &n, &m, &k);

	//火把
	for (int i = 1; i <= m; i++)
	{
		scanf("%d %d", &x, &y);
		//防止数组越界
		x += 2;
		y += 2;
		for (int l = x - 1; l <= x + 1; l++)
			for (int p = y - 1; p <= y + 1; p++)
				a[l][p] = 1; //火把中间3*3的范围
		a[x - 2][y] = a[x + 2][y] = a[x][y - 2] = a[x][y + 2] = 1; //剩下的四个点单独标记
	}

	//萤石
	for (int i = 1; i <= k; i++)
	{
		scanf("%d %d", &x, &y);
		//防止数组越界
		x += 2;
		y += 2;
		for (int l = x - 2; l <= x + 2; l++)
			for (int p = y - 2; p <= y + 2; p++)
				a[l][p] = 1; //因为萤石的范围是5*5所以直接标记
	}

	//遍历
	for (int i = 1 + 2; i <= n + 2; i++) //+2后正常进行
		for (int j = 1 + 2; j <= n + 2; j++)
			if (a[i][j] == 0) //未标记即为没有光生怪处
				ans++;
	printf("%d\n", ans);
	return 0;
}

 

你可能感兴趣的:(c++,c语言)