MapleStory Finger Point

๐Ÿƒ‍โ™‚๏ธBaekjoon/Python

#2563 -python

HYEJU01 2024. 4. 27. 00:11
N = int(input()) #์ƒ‰์ข…์ด ๊ฐœ์ˆ˜

arr = [[0 for _ in range (100)] for _ in range(101)]

for _ in range (N):
    x,y = list(map(int,input().split())) #๊ฐ’ ๋ฐ›์•„์˜ค๊ธฐ

    for row in range(x,x+10): # 10 x 10 ๊ณ ์ • ๊ฐ’
        for col in range (y,y+10):
            arr[row][col] = 1 #์ƒ‰์ข…์ด์˜ ๋„“์ด ํ‘œํ˜„
    
result = 0

for i in arr:
    result += i.count(1)
print(result)

 

2์ฐจ์›๋ฐฐ์—ด์˜ ์ดˆ๊ธฐ๊ฐ’์€ 0์œผ๋กœ ์žก์•„์ฃผ๊ณ 

x ~ x+10 ๋งŒํผ 1์„ ์ฐ์–ด์ค˜์„œ ์ƒ‰์ข…์ด์˜ ๋„“์ด๋ฅผ ํ‘œํ˜„ํ•ด์ค€๋‹ค.

์ดํ›„ 1์˜ ๊ฐœ์ˆ˜๋งŒ ์„ธ์–ด์ฃผ๋ฉด ๋„“์ด๋ฅผ ๊ตฌํ•  ์ˆ˜ ์žˆ๋‹ค.

 

 

<< ๐Ÿคฎ ๋ง‰ํžŒ ์ด์œ  & ํ•ด๊ฒฐ  >>

 

๋„“์ด ๊ตฌํ•˜๋Š” ๊ฑธ ๊ณต์‹์„ ์‚ฌ์šฉํ•ด์„œ ์ ‘๊ทผํ•ด์•ผํ•˜๋‚˜..? ๋ณต์žกํ•ด์ง€๋Š”๋ฐ ์ƒ๊ฐ๋“ค์—ˆ๋Š”๋ฐ

๊ฐ„๋‹จ๋ช…๋ฃŒํ•œ ์ฝ”๋“œ๊ฐ€ ์žˆ์–ด์„œ ๊ฐ€์ ธ์™”๋‹ค!

 

 

๐Ÿ’ฌ [[0 for _ in range (100)] for _ in range(101)] 

์ด์ค‘ ๋ฆฌ์ŠคํŠธ ์ปดํ”„๋ฆฌํ—จ์…˜์€ ํŒŒ์ด์ฌ์—์„œ ๋ฆฌ์ŠคํŠธ๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๊ฐ„๊ฒฐํ•˜๊ณ  ํšจ์œจ์ ์ธ ๋ฐฉ๋ฒ• ์ค‘ ํ•˜๋‚˜์ž…๋‹ˆ๋‹ค.

์ด๋Š” ๋‚ดํฌ๋œ ๋ฃจํ”„๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฆฌ์ŠคํŠธ๋ฅผ ์ƒ์„ฑํ•˜๋Š”๋ฐ,

๋‚ด๋ถ€ ๋ฆฌ์ŠคํŠธ ์ปดํ”„๋ฆฌํ—จ์…˜์€ ์™ธ๋ถ€ ๋ฆฌ์ŠคํŠธ ์ปดํ”„๋ฆฌํ—จ์…˜์˜ ๊ฐ ์š”์†Œ์— ๋Œ€ํ•ด ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค.

๊ฐ„๋‹จํ•œ ์˜ˆ์ œ๋ฅผ ํ†ตํ•ด ์„ค๋ช…ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค:

matrix = [[i * j for j in range(1, 4)] for i in range(1, 4)]
print(matrix)

 

์œ„ ์ฝ”๋“œ๋Š” 3x3 ํ–‰๋ ฌ์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. ๋‚ด๋ถ€ ๋ฆฌ์ŠคํŠธ ์ปดํ”„๋ฆฌํ—จ์…˜ [i * j for j in range(1, 4)]์€ ์™ธ๋ถ€ ๋ฆฌ์ŠคํŠธ ์ปดํ”„๋ฆฌํ—จ์…˜ for i in range(1, 4)์˜ ๊ฐ ์š”์†Œ์— ๋Œ€ํ•ด ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค. ๊ฒฐ๊ณผ์ ์œผ๋กœ ์™ธ๋ถ€ ๋ฆฌ์ŠคํŠธ๋Š” [1, 2, 3], [2, 4, 6], [3, 6, 9]๋กœ ๊ตฌ์„ฑ๋˜๋ฉฐ,

3x3 ํ–‰๋ ฌ์ด ๋งŒ๋“ค์–ด์ง‘๋‹ˆ๋‹ค.

์ด์ค‘ ๋ฆฌ์ŠคํŠธ ์ปดํ”„๋ฆฌํ—จ์…˜์€ ์ฝ”๋“œ๋ฅผ ๊ฐ„๊ฒฐํ•˜๊ฒŒ ์œ ์ง€ํ•˜๋ฉด์„œ ๋‹ค์ฐจ์› ๋ฆฌ์ŠคํŠธ๋ฅผ ์ดˆ๊ธฐํ™”ํ•  ๋•Œ ๋งค์šฐ ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค.

 

๐Ÿ’ฌ .count  i.count(1)์€ ๋ฆฌ์ŠคํŠธ i ์•ˆ์— ์ˆซ์ž 1์ด ๋ช‡ ๋ฒˆ ๋“ฑ์žฅํ•˜๋Š”์ง€๋ฅผ ๋ฐ˜ํ™˜