抽象题解py
2024-10-08 22:41:56
发布于:湖南
30阅读
0回复
0点赞
抽象
from array import array
def solve1(x1, y1, x2, y2):
res = 0
uy = y1 - 1
dy = y1 + 1
if a[x1][uy][1] and a[x2][uy][1] and a[x1][uy][0]:
res += 1
if a[x1][dy][3] and a[x2][dy][3] and a[x1][dy][0]:
res += 1
return res
def solve2(x1, y1, x2, y2):
res = 0
uy = y1 - 1
dy = y1 + 1
if a[x1][uy][1] and a[x2][uy][1] and a[x1][uy][2]:
res += 1
if a[x1][dy][3] and a[x2][dy][3] and a[x1][dy][2]:
res += 1
return res
def solve3(x1, y1, x2, y2):
res = 0
ux = x1 - 1
dx = x1 + 1
if a[ux][y1][0] and a[ux][y2][0] and a[ux][y1][1]:
res += 1
if a[dx][y1][2] and a[dx][y2][2] and a[dx][y1][1]:
res += 1
return res
def solve4(x1, y1, x2, y2):
res = 0
ux = x1 - 1
dx = x1 + 1
if a[ux][y1][0] and a[ux][y2][0] and a[ux][y1][3]:
res += 1
if a[dx][y1][2] and a[dx][y2][2] and a[dx][y1][3]:
res += 1
return res
n, m, Q = map(int, input().split())
a = [[array('i', [0] * 4) for _ in range(m + 5)] for _ in range(n + 5)]
ans1 = ans2 = 0
for _ in range(Q):
x1, y1, x2, y2 = map(int, input().split())
if x2 == x1 + 1:
a[x1][y1][0] = 1
a[x2][y1][2] = 1
ans1 += solve1(x1, y1, x2, y2)
elif x1 == x2 + 1:
a[x1][y1][2] = 1
a[x2][y1][0] = 1
ans1 += solve2(x1, y1, x2, y2)
elif y2 == y1 + 1:
a[x1][y1][1] = 1
a[x1][y2][3] = 1
ans1 += solve3(x1, y1, x2, y2)
else:
a[x1][y1][3] = 1
a[x1][y2][1] = 1
ans1 += solve4(x1, y1, x2, y2)
x1, y1, x2, y2 = map(int, input().split())
if x2 == x1 + 1:
a[x1][y1][0] = 1
a[x2][y1][2] = 1
ans2 += solve1(x1, y1, x2, y2)
elif x1 == x2 + 1:
a[x1][y1][2] = 1
a[x2][y1][0] = 1
ans2 += solve2(x1, y1, x2, y2)
elif y2 == y1 + 1:
a[x1][y1][1] = 1
a[x1][y2][3] = 1
ans2 += solve3(x1, y1, x2, y2)
else:
a[x1][y1][3] = 1
a[x1][y2][1] = 1
ans2 += solve4(x1, y1, x2, y2)
print(ans1, ans2)
这里空空如也
有帮助,赞一个