N° Studio logoHarutoStudio
GuidesArticlesPremium
Dashboard
GuidesArticlesPremium
Blog/APCS Jun 2024 - o077
  • #apcs

APCS Jun 2024 - o077

BlackInkBlackInkJune 19, 2025 at 08:00 AM
On this page APCS Jun 2024 - o077 Q2 [Python]
  1. APCS Jun 2024 - o077 Q2 [Python]
  2. Important points

APCS Jun 2024 - o077 Q2 [Python]

Problem statement:

An H × W electronic canvas starts with every value set to 0, meaning uncolored. Simulate N brush operations. Each operation selects coordinates (r, c) and stays there for t seconds, adding color value x to all cells at Manhattan distance ≤ t. When colors overlap, their values are added. Output the canvas after all N operations.

H,W,N = map(int,input().split())

a = [[0 for _ in range(W)] for _ in range(H)]

for _ in range(N):
    r,c,time,num = map(int,input().split())
    for rr in range(r - time,r + time + 1):
        for cc in range(c - time , c + time +1):
            if 0 <= rr < H and 0 <= cc < W and abs(rr - r)+ abs(cc-c) <= time: # 曼哈頓距離公式
                a[rr][cc] += num

for i in a:
    for j in i:
        print(j,end=' ')
    print('\n', end='')



Important points

  1. Manhattan distance: On an orthogonal grid, this distance is the sum of the horizontal and vertical distances between two points. For (r, c) and (rr, cc), the formula is:
    • D = |rr - r| + |cc - c|

Key concepts:

  • Simulation?

  • [✔️] You may use the code directly if needed.
  • [✔️] Please credit the source when sharing.

image

This article was translated from Traditional Chinese by AI. Meaning or wording may differ; please refer to the Traditional Chinese original as the authoritative version.

On this page

  1. APCS Jun 2024 - o077 Q2 [Python]
  2. Important points
HarutoStudio LogoHarutoStudio

HarutoStudio © 2023 - 2026

Links

  • Documentation
  • Dashboard
  • Terms of service
  • Privacy policy
  • Refund policy
  • Bot status

Community

  • Discord
  • Github
  • Instagram
  • top.gg

Support us

  • Premium plans
  • Partners