话说有一天 linyorson 在“我的世界”开了一个 n × n n \times n n×n 的方阵,现在他有 m m m 个火把和 k k k 个萤石,分别放在 ( x 1 , y 1 ) ~ ( x m , y m ) (x_1, y_1) \sim (x_m, y_m) (x1?,y1?)~(xm?,ym?) 和 ( o 1 , p 1 ) ~ ( o k , p k ) (o_1, p_1) \sim (o_k, p_k) (o1?,p1?)~(ok?,pk?) 的位置,没有光并且没放东西的地方会生成怪物。请问在这个方阵中有几个点会生成怪物?
P.S. 火把的照亮范围是:
|暗|暗| 光 |暗|暗|
|暗|光| 光 |光|暗|
|光|光|火把|光|光|
|暗|光| 光 |光|暗|
|暗|暗| 光 |暗|暗|
萤石:
|光|光| 光 |光|光|
|光|光| 光 |光|光|
|光|光|萤石|光|光|
|光|光| 光 |光|光|
|光|光| 光 |光|光|
输入共
m
+
k
+
1
m + k + 1
m+k+1 行。
第一行为
n
,
m
,
k
n, m, k
n,m,k。
第
2
2
2 到第
m
+
1
m + 1
m+1 行分别是火把的位置
x
i
,
y
i
x_i, y_i
xi?,yi?。
第
m
+
2
m + 2
m+2 到第
m
+
k
+
1
m + k + 1
m+k+1 行分别是萤石的位置
o
i
,
p
i
o_i, p_i
oi?,pi?。
注:可能没有萤石,但一定有火把。
有几个点会生出怪物。
5 1 0
3 3
12
数据保证, 1 ≤ n ≤ 100 1 \le n \le 100 1≤n≤100, 1 ≤ m + k ≤ 25 1 \leq m+k \leq 25 1≤m+k≤25, 1 ≤ m ≤ 25 1 \leq m \leq 25 1≤m≤25, 0 ≤ k ≤ 5 0 \leq k \leq 5 0≤k≤5。
n,m,k=map(int,input().split())
mapp=[[0]*(n+1) for _ in range(n+1)]
for item in range(m):
x,y=map(int,input().split())
mapp[x][y]=2
if x-1>=1:
mapp[x-1][y]=1
if y-1>=1:
mapp[x-1][y-1]=1
pass
pass
if x+1<=n:
mapp[x+1][y]=1
if y+1<=n:
mapp[x+1][y+1]=1
pass
pass
if x-2>=1:
mapp[x-2][y]=1
pass
if x+2<=n:
mapp[x+2][y]=1
pass
if y-1>=1:
mapp[x][y-1]=1
if x+1<=n:
mapp[x+1][y-1]=1
pass
pass
if y+1<=n:
mapp[x][y+1]=1
if x-1>=1:
mapp[x-1][y+1]=1
pass
pass
if x-2>=1:
mapp[x][y-2]=1
pass
if x+2<=n:
mapp[x][y+2]=1
pass
pass
for item in range(k):
x, y = map(int, input().split())
mapp[x][y]=3
if x+1<=n:
mapp[x+1][y]=1
if y+1<=n:
mapp[x+1][y+1]=1
pass
if y-1>=1:
mapp[x+1][y-1]=1
pass
if y+2<=n:
mapp[x+1][y+2]=1
pass
if y-2>=1:
mapp[x+1][y-2]=1
pass
if x-1>=1:
mapp[x-1][y]=1
if y+1<=n:
mapp[x-1][y+1]=1
pass
if y-1>=1:
mapp[x-1][y-1]=1
pass
if y+2<=n:
mapp[x-1][y+2]=1
pass
if y-2>=1:
mapp[x-1][y-2]=1
pass
if y+1<=n:
mapp[x][y+1]=1
if x+1<=n:
mapp[x+1][y+1]=1
pass
if x-1>=1:
mapp[x-1][y+1]=1
pass
if x+2<=n:
mapp[x+2][y+1]=1
pass
if x-2>=1:
mapp[x-2][y+1]=1
pass
if y-1>=0:
mapp[x][y-1]=1
if x+1<=n:
mapp[x+1][y-1]=1
pass
if x-1>=1:
mapp[x-1][y-1]=1
pass
if x+2<=n:
mapp[x+2][y-1]=1
pass
if x-2>=1:
mapp[x-2][y-1]=1
pass
if x+2<=n:
mapp[x+2][y]=1
if y+2<=n:
mapp[x+2][y+2]=1
pass
if y-2>=1:
mapp[x+2][y-2]=1
pass
pass
if x-2>=1:
mapp[x-2][y]=1
if y+2<=n:
mapp[x-2][y+2]=1
pass
if y-2>=1:
mapp[x-2][y-2]=1
pass
pass
if y+2<=n:
mapp[x][y+2]=1
pass
if y-2>=1:
mapp[x][y-2]=1
pass
pass
anss=0
for item in range(1,n+1):
for jtem in range(1,n+1):
if mapp[item][jtem]==0:
anss+=1
pass
pass
pass
print(anss)
一眼放去全是if,不难的题,注意边界超出以及题目中数组起始值为1就行,再就是有耐心把代码写完,这些判断应该还可以优化很多,但是不太爱动脑子,快点把入门刷完