This commit is contained in:
2024-12-11 17:31:43 +08:00
parent fdaa94a0fa
commit 5e6299439c
6 changed files with 182 additions and 19 deletions

View File

@@ -1,27 +1,39 @@
# Unfinish
from typing import Tuple, List
import math
n, m, r = input().split(" ")
locations: List[Tuple[str, str]] = []
for i in range(int(m)):
location: Tuple[str, str] = tuple(input().split(" "))
locations.append(location)
n, m, r = map(int, input().split())
locations: List[Tuple[int, int]] = []
map = [[0 for _ in range(int(n))] for _ in range(int(n))]
for i in range(m):
x, y = map(int, input().split())
# 将输入的1-based坐标转换为0-based坐标
locations.append((x - 1, y - 1))
grid = [[0 for _ in range(n)] for _ in range(n)]
count = 0
for i in range(int(n)):
for j in range(int(n)):
if map[i][j] == 0:
for k in range(int(m)):
distance = math.sqrt(
(int(locations[k][0]) - i) ** 2 + (int(locations[k][1]) - j) ** 2
)
if distance <= float(r):
map[i][j] = 1
count = count + 1
break
for location in locations:
x, y = location
if grid[x][y] != 1:
grid[x][y] = 1
count += 1
# 检查半径r内的所有点
left = max(0, x - r)
right = min(n, x + r + 1)
top = max(0, y - r)
bottom = min(n, y + r + 1)
for i in range(left, right):
for j in range(top, bottom):
# 计算点(i,j)到探测器(x,y)的距离
distance = math.sqrt((i - x) ** 2 + (j - y) ** 2)
if distance <= r: # 如果在探测范围内
if grid[i][j] != 1:
grid[i][j] = 1
count += 1
print(count)
print(map)
for row in grid:
print(row)