ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [๋ฐฑ์ค€] 20125 ์ฟ ํ‚ค์˜ ์‹ ์ฒด ์ธก์ • with Python
    PS 2022. 5. 12. 01:38
    728x90
    ๋ฐ˜์‘ํ˜•

    ๐Ÿ“Œ BOJ 20125 ์ฟ ํ‚ค์˜ ์‹ ์ฒด ์ธก์ •

    ๐Ÿ’ก ์กฐ๊ฑด

    1. ์ฟ ํ‚ค๋“ค์€ ์‹ ์ฒด๋ฅผ ์ธก์ •ํ•˜๊ธฐ ์œ„ํ•ด์„œ ํ•œ ๋ณ€์˜ ๊ธธ์ด๊ฐ€ N์ธ ์ •์‚ฌ๊ฐํ˜• ํŒ ์œ„์— ๋ˆ„์›Œ์žˆ์œผ๋ฉฐ, ์–ด๋Š ์‹ ์ฒด ๋ถ€์œ„๋„ ํŒ ๋ฐ–์œผ๋กœ ๋ฒ—์–ด๋‚˜์ง€ ์•Š๋Š”๋‹ค.
    2. ํŒ์˜ x๋ฒˆ์งธ ํ–‰, y๋ฒˆ์งธ ์—ด์— ์œ„์น˜ํ•œ ๊ณณ์„ (x, y)๋กœ ์ง€์นญํ•œ๋‹ค. ํŒ์˜ ๋งจ ์™ผ์ชฝ ์œ„ ์นธ์„ (1, 1), ์˜ค๋ฅธ์ชฝ ์•„๋ž˜ ์นธ์„ (N, N)์œผ๋กœ ๋‚˜ํƒ€๋‚ผ ์ˆ˜ ์žˆ๋‹ค.
    3. ์ฟ ํ‚ค์˜ ์‹ ์ฒด๋Š” ๋จธ๋ฆฌ, ์‹ฌ์žฅ, ํ—ˆ๋ฆฌ, ๊ทธ๋ฆฌ๊ณ  ์ขŒ์šฐ ํŒ”, ๋‹ค๋ฆฌ๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ๋‹ค.

    1. ๊ทธ๋ฆผ์—์„œ ๋นจ๊ฐ„ ๊ณณ์œผ๋กœ ์น ํ•ด์ง„ ๋ถ€๋ถ„์ด ์‹ฌ์žฅ์ด๋‹ค. ๋จธ๋ฆฌ๋Š” ์‹ฌ์žฅ ๋ฐ”๋กœ ์œ— ์นธ์— 1์นธ ํฌ๊ธฐ๋กœ ์žˆ๋‹ค.
      ์™ผ์ชฝ ํŒ”์€ ์‹ฌ์žฅ ๋ฐ”๋กœ ์™ผ์ชฝ์— ๋ถ™์–ด์žˆ๊ณ  ์™ผ์ชฝ์œผ๋กœ ๋ป—์–ด ์žˆ์œผ๋ฉฐ, ์˜ค๋ฅธ์ชฝ ํŒ”์€ ์‹ฌ์žฅ ๋ฐ”๋กœ ์˜ค๋ฅธ์ชฝ์— ๋ถ™์–ด์žˆ๊ณ  ์˜ค๋ฅธ์ชฝ์œผ๋กœ ๋ป—์–ด์žˆ๋‹ค.
      ํ—ˆ๋ฆฌ๋Š” ์‹ฌ์žฅ์˜ ๋ฐ”๋กœ ์•„๋ž˜ ์ชฝ์— ๋ถ™์–ด์žˆ๊ณ  ์•„๋ž˜ ์ชฝ์œผ๋กœ ๋ป—์–ด ์žˆ๋‹ค.
      ์™ผ์ชฝ ๋‹ค๋ฆฌ๋Š” ํ—ˆ๋ฆฌ์˜ ์™ผ์ชฝ ์•„๋ž˜์—, ์˜ค๋ฅธ์ชฝ ๋‹ค๋ฆฌ๋Š” ํ—ˆ๋ฆฌ์˜ ์˜ค๋ฅธ์ชฝ ์•„๋ž˜์— ๋ฐ”๋กœ ๋ถ™์–ด์žˆ๊ณ , ๊ฐ ๋‹ค๋ฆฌ๋“ค์€ ์ „๋ถ€ ์•„๋ž˜์ชฝ์œผ๋กœ ๋ป—์–ด ์žˆ๋‹ค.
      ๊ฐ ์‹ ์ฒด ๋ถ€์œ„๋“ค์€ ์ ˆ๋Œ€๋กœ ๋Š๊ฒจ์žˆ์ง€ ์•Š์œผ๋ฉฐ ๊ตฝํ˜€์ง„ ๊ณณ๋„ ์—†๋‹ค.
      ๋˜ํ•œ, ํ—ˆ๋ฆฌ, ํŒ”, ๋‹ค๋ฆฌ์˜ ๊ธธ์ด๋Š” 1 ์ด์ƒ์ด๋ฉฐ, ๋„ˆ๋น„๋Š” ๋ฌด์กฐ๊ฑด 1์ด๋‹ค.

    2. ์ฟ ํ‚ค์˜ ์‹ ์ฒด๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ ์‹ฌ์žฅ์˜ ์œ„์น˜์™€ ํŒ”, ๋‹ค๋ฆฌ, ํ—ˆ๋ฆฌ์˜ ๊ธธ์ด๋ฅผ ๊ตฌํ•˜๋Š” ๋ฌธ์ œ

    3. 5 โ‰ค N โ‰ค 1,000. N์€ ํŒ์˜ ํ•œ ๋ณ€์˜ ๊ธธ์ด๋ฅผ ์˜๋ฏธํ•˜๋Š” ์–‘์˜ ์ •์ˆ˜๋‹ค.

    4. ai,j๋Š” * ๋˜๋Š” _์ด๋‹ค. *๋Š” ์ฟ ํ‚ค์˜ ์‹ ์ฒด ๋ถ€๋ถ„์ด๊ณ , _๋Š” ์ฟ ํ‚ค์˜ ์‹ ์ฒด๊ฐ€ ์˜ฌ๋ผ๊ฐ€ ์žˆ์ง€ ์•Š์€ ์นธ์„ ์˜๋ฏธํ•œ๋‹ค. (1 โ‰ค i, j โ‰ค N)

    5. ์ฟ ํ‚ค์˜ ์‹ ์ฒด ์กฐ๊ฑด์— ์œ„๋ฐฐ๋˜๋Š” ์ž…๋ ฅ์€ ์ฃผ์–ด์ง€์ง€ ์•Š๋Š”๋‹ค.

    6. ๊ตฌํ˜„ ์œ ํ˜•์˜ ๋ฌธ์ œ

    ๐Ÿ–ฅ ์†Œ์Šค ์ฝ”๋“œ

    from sys import stdin
    
    arr = []
    n = int(stdin.readline())
    for i in range(n):
        arr.append(list(stdin.readline().rstrip()))
    
    heo, l_leg, r_leg = 0, 0, 0
    
    
    def find_heart():
        for i in range(n):
            for j in range(n):
                if arr[i][j] == '*':
                    return (i, j), (i + 1, j)
    
    
    head, heart = find_heart()
    
    
    l_arm = arr[heart[0]][:heart[1]].count('*')
    r_arm = arr[heart[0]][heart[1] + 1:].count('*')
    
    for i in range(heart[0] + 1, n):
        if arr[i][heart[1]] != '*':
            last_heo = (i, heart[1])
            break
        else:
            heo += 1
    
    for i in range(last_heo[0], n):
        if arr[i][heart[1] - 1] == '*':
            l_leg += 1
    
        if arr[i][heart[1] + 1] == '*':
            r_leg += 1
    
    
    print(heart[0] + 1, heart[1] + 1)
    print(l_arm, r_arm, heo, l_leg, r_leg)

    ๐Ÿ”– ์˜ˆ์ œ ๋ฐ ์‹คํ–‰๊ฒฐ๊ณผ

    ์˜ˆ์ œ

    5
    _____
    __*__
    _***_
    __*__
    _*_*_

    ์‹คํ–‰๊ฒฐ๊ณผ

    3 3
    1 1 1 1 1
    ๋ฐ˜์‘ํ˜•

    ๋Œ“๊ธ€

Designed by Tistory.