洛谷——P1789 【Mc生存】插火把

题目描述
话说有一天 linyorson 在“我的世界”开了一个 n×n(n≤100) 的方阵,现在他有 m 个火把和 k 个萤石,分别放在 (x1,y1)…(xm,ym)和(o1,p1)…(ok,pk) 的位置,没有光或没放东西的地方会生成怪物。请问在这个方阵中有几个点会生成怪物?

P.S.火把的照亮范围是:

|暗|暗| 光 |暗|暗|
|暗|光| 光 |光|暗|
|光|光|火把|光|光|
|暗|光| 光 |光|暗|
|暗|暗| 光 |暗|暗|

萤石:

|光|光| 光 |光|光|
|光|光| 光 |光|光|
|光|光|萤石|光|光|
|光|光| 光 |光|光|
|光|光| 光 |光|光|

输入格式
输入共m+k+1行。
第一行为n,m,k。
第2到第m+1行分别是火把的位置xi yi。
第m+2到第m+k+1行分别是萤石的位置oi pi。
注:可能没有萤石,但一定有火把。

所有数据保证在int范围内。

输出格式
有几个点会生出怪物。

输入输出样例
输入 #1
5 1 0
3 3
输出 #1
12

输入 #2
100 1 1
50 50
3 3
输出 #2
9962

我的答案:
使用的暴力模拟,很复杂。
使用了两个结构体数组,加一个二维数组。

#include<stdio.h>
#define MAX 100

struct FIGHT
{
	int hengzb;
	int zongzb;
};
struct FIGYH
{
	int HengZB;
	int ZongZB;
};
int main()
{
	int n, m, k,temp1,temp2,temp3,temp4,count = 0;
	int a[MAX][MAX] = { 0 };
	struct FIGHT fig[MAX];
	struct FIGYH fyh[MAX];
	scanf("%d %d %d", &n, &m, &k);
	for (int i = 0; i < m + 1 - 2 + 1; i++)
	{
		scanf("%d%d",&fig[i].hengzb,&fig[i].zongzb);
		temp1 = fig[i].hengzb - 1;
		temp2 = fig[i].zongzb - 1;
		a[temp1][temp2] = 1;
		a[temp1][temp2 - 1] = 1;
		a[temp1][temp2 - 2] = 1;
		a[temp1][temp2 + 1] = 1;
		a[temp1][temp2 + 2] = 1;
		a[temp1 - 1][temp2] = 1;
		a[temp1 - 2][temp2] = 1;
		a[temp1 + 1][temp2] = 1;
		a[temp1 + 2][temp2] = 1;
		a[temp1 - 1][temp2 - 1] = 1;
		a[temp1 - 1][temp2 + 1] = 1;
		a[temp1 + 1][temp2 + 1] = 1;
		a[temp1 + 1][temp2 - 1] = 1;
	}
	for (int i = 0; i <  k ; i++)
	{
		scanf("%d%d", &fyh[i].HengZB, &fyh[i].ZongZB);
		temp3 = fyh[i].HengZB - 1;
		temp4 = fyh[i].ZongZB - 1;
		a[temp3][temp4] = 1;
		a[temp3][temp4 - 1] = 1;
		a[temp3][temp4 - 2] = 1;
		a[temp3][temp4 + 1] = 1;
		a[temp3][temp4 + 2] = 1;
		a[temp3 - 1][temp4] = 1;
		a[temp3 - 2][temp4] = 1;
		a[temp3 + 1][temp4] = 1;
		a[temp3 + 2][temp4] = 1;
		a[temp3 - 1][temp4 - 1] = 1;
		a[temp3 - 1][temp4 + 1] = 1;
		a[temp3 + 1][temp4 + 1] = 1;
		a[temp3 + 1][temp4 - 1] = 1;
		a[temp3 - 2][temp4 - 2] = 1;
		a[temp3 - 2][temp4 - 1] = 1;
		a[temp3 - 2][temp4 + 1] = 1;
		a[temp3 - 2][temp4 + 2] = 1;
		a[temp3 - 1][temp4 - 2] = 1;
		a[temp3 - 1][temp4 + 2] = 1;
		a[temp3 + 1][temp4 - 2] = 1;
		a[temp3 + 1][temp4 + 2] = 1;
		a[temp3 + 2][temp4 - 2] = 1;
		a[temp3 + 2][temp4 - 1] = 1;
		a[temp3 + 2][temp4 + 1] = 1;
		a[temp3 + 2][temp4 + 2] = 1;
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if (a[i][j] == 1)
			{
				count++;
			}
			else
			{
				continue;
			}
		}
	}
	printf("%d", n * n - count);
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值