2397: 【入门】【P1789】插火把

内存限制:128 MB 时间限制:1.000 S
评测方式:文本比较 命题人:
提交:59 解决:17

题目描述

话说有一天 linyorson 在“我的世界”开了一个 lns="http://www.w3.org/1998/Math/MathML">× 的方阵,现在他有 lns="http://www.w3.org/1998/Math/MathML"> 个火把和 lns="http://www.w3.org/1998/Math/MathML"> 个萤石,分别放在 lns="http://www.w3.org/1998/Math/MathML">(1,1)(,) 和 lns="http://www.w3.org/1998/Math/MathML">(1,1)(,) 的位置,没有光并且没放东西的地方会生成怪物。请问在这个方阵中有几个点会生成怪物?

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

 ||||||
 ||||||
 |||火把|||
 ||||||
 |||||| 

萤石:

 ||||||
 ||||||
 |||萤石|||
 ||||||
 |||||| 

输入

输入共 lns="http://www.w3.org/1998/Math/MathML">++1 行。
第一行为 lns="http://www.w3.org/1998/Math/MathML">,,
第 lns="http://www.w3.org/1998/Math/MathML">2 到第 lns="http://www.w3.org/1998/Math/MathML">+1 行分别是火把的位置 lns="http://www.w3.org/1998/Math/MathML">,
第 lns="http://www.w3.org/1998/Math/MathML">+2 到第 lns="http://www.w3.org/1998/Math/MathML">++1 行分别是萤石的位置 lns="http://www.w3.org/1998/Math/MathML">,

注:可能没有萤石,但一定有火把。

输出

有几个点会生出怪物。

样例输入 复制

5 1 0
3 3

样例输出 复制

12

提示

数据保证,lns="http://www.w3.org/1998/Math/MathML">1100lns="http://www.w3.org/1998/Math/MathML">1+25lns="http://www.w3.org/1998/Math/MathML">125lns="http://www.w3.org/1998/Math/MathML">05


#include<iostream>
#include<cstring>
using namespace std;
int a[110][110];
int h[13][2]={{0,0},{1,0},{2,0},{-1,0},{-2,0},{0,1},{0,2},{0,-1},{0,-2},{1,1},{-1,1},{-1,-1},{1,-1}};  //偏移数组
int main(){
	int n,m,k,ans=0,x,y;
	cin>>n>>m>>k;
	for (int i=1;i<=m;i++){
		cin>>x>>y;
		for (int j=0;j<13;j++) {
			if (x+h[j][0]>=1 && y+h[j][1]>=1 && x+h[j][0]<=n && y+h[j][1]<=n) //下标的合法性判断
			    a[x+h[j][0]][y+h[j][1]]=1;
		}
	}
	for (int i=1;i<=k;i++) {
		cin>>x>>y;
		for (int j=x-2;j<=x+2;j++) {
			for (int t=y-2;t<=y+2;t++){
				if (j>=1 && t>=1 && j<=n && t<=n) //下标的合法性判断
				    a[j][t]=1;
			}
		}
	}
	for (int i=1;i<=n;i++) {
		for (int j=1;j<=n;j++) {
			if (a[i][j]==0) ans++;
		}
	}
	cout<<ans;
	return 0;
}