๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿ‡ฆ๐Ÿ‡ฑ๐Ÿ‡ฌ๐Ÿ‡ด๐Ÿ‡ท๐Ÿ‡ฎ๐Ÿ‡น๐Ÿ‡ญ๐Ÿ‡ฒ

[์ด์ฝ”ํ…Œ] ๊ตฌํ˜„

์ฐธ๊ณ ์ž๋ฃŒ: ์ด๊ฒƒ์ด ์ฝ”๋”ฉ ํ…Œ์ŠคํŠธ๋‹ค with ํŒŒ์ด์ฌ

 

๊ตฌํ˜„

๋จธ๋ฆฟ์†์— ์žˆ๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์†Œ์Šค ์ฝ”๋“œ๋กœ ๋ฐ”๊พธ๋Š” ๊ณผ์ •
problem - thinking - solution

 

์˜ˆ์ œ 1 - ์ƒํ•˜์ขŒ์šฐ

 

์—ฌํ–‰๊ฐ€ A๋Š” N x N ํฌ๊ธฐ์˜ ์ •์‚ฌ๊ฐํ˜• ๊ณต๊ฐ„ ์œ„์— ์„œ ์žˆ๋‹ค. ์ด ๊ณต๊ฐ„์€ 1 x 1 ํฌ๊ธฐ์˜ ์ •์‚ฌ๊ฐํ˜•์œผ๋กœ ๋‚˜๋ˆ„์–ด์ ธ์žˆ๋‹ค. ๊ฐ€์žฅ ์™ผ์ชฝ ์œ„ ์ขŒํ‘œ๋Š” (1,1) ์ด๋ฉฐ, ๊ฐ€์žฅ ์˜ค๋ฅธ์ชฝ ์•„๋ž˜ ์ขŒํ‘œ๋Š” (N,N)์— ํ•ด๋‹นํ•œ๋‹ค. ์—ฌํ–‰๊ฐ€ A๋Š” ์ƒ, ํ•˜, ์ขŒ, ์šฐ ๋ฐฉํ–ฅ์œผ๋กœ ์ด๋™ํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ์‹œ์ž‘ ์ขŒํ‘œ๋Š” ํ•ญ์ƒ (1,1)์ด๋‹ค. ์šฐ๋ฆฌ ์•ž์—๋Š” ์—ฌํ–‰๊ฐ€ A๊ฐ€ ์ด๋™ํ•  ๊ณ„ํš์ด ์ ํžŒ ๊ณ„ํš์„œ๊ฐ€ ๋†“์—ฌ ์žˆ๋‹ค.

 

๋‹ค์Œ์€ N = 5์ธ ์ง€๋„์™€ ๊ณ„ํš์„œ

R → R → R → U → D → D

(1,1) (1,2) (1,3) (1,4) (1,5)
(2,1) (2,2) (2,3) (2,4) (2,5)
(3,1) (3,2) (3,3) (3,4) (3,5)
(4,1) (4,2) (4,3) (4,4) (4,5)
(5,1) (5,2) (5,3) (5,4) (5,5)

 

โœ” ๊ณ„ํš์„œ๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ ์—ฌํ–‰๊ฐ€ A๊ฐ€ ์ตœ์ข…์ ์œผ๋กœ ๋„์ฐฉํ•  ์ง€์ ์˜ ์ขŒํ‘œ๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ

  • ์ฒซ์งธ ์ค„์— ๊ณต๊ฐ„์˜ ํฌ๊ธฐ๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” N์ด ์ฃผ์–ด์ง„๋‹ค. (1 ≤ N ≤ 100)
  • ๋‘˜์งธ ์ค„์— ์—ฌํ–‰๊ฐ€ A๊ฐ€ ์ด๋™ํ•  ๊ณ„ํš์„œ ๋‚ด์šฉ์ด ์ฃผ์–ด์ง„๋‹ค. (1 ≤ ์ด๋™ ํšŸ์ˆ˜ ≤ 100)
  • ์ฒซ์งธ ์ค„์— ์—ฌํ–‰๊ฐ€ A๊ฐ€ ์ตœ์ข…์ ์œผ๋กœ ๋„์ฐฉํ•  ์ง€์ ์˜ ์ขŒํ‘œ (X, Y)๋ฅผ ๊ณต๋ฐฑ์œผ๋กœ ๊ตฌ๋ถ„ํ•˜์—ฌ ์ถœ๋ ฅํ•œ๋‹ค.
# N ์ž…๋ ฅ๋ฐ›๊ธฐ
n = int(input())
x, y = 1, 1
plan = input().split()

dx = {'L':0, 'R':0, 'U':-1, 'D':1}
dy = {'L':-1, 'R':1, 'U':0, 'D':0}

for i in plan:
    nx = x + dx[i]
    ny = y + dy[i]
    
    #๊ณต๊ฐ„์„ ๋ฒ—์–ด๋‚˜๋Š” ๊ฒฝ์šฐ ๋ฌด์‹œ
    if nx < 1 or ny < 1 or nx > n or ny > n:
        continue
    
    x, y = nx, ny
    
print(x, y)
# N ์ž…๋ ฅ๋ฐ›๊ธฐ
n = int(input())
x, y = 1, 1
plan = input().split()

dx = {'L':0, 'R':0, 'U':-1, 'D':1}
dy = {'L':-1, 'R':1, 'U':0, 'D':0}

for i in plan:
    nx = x + dx[i]
    ny = y + dy[i]
    
    #๊ณต๊ฐ„์„ ๋ฒ—์–ด๋‚˜๋Š” ๊ฒฝ์šฐ ๋ฌด์‹œ
    if nx < 1 or ny < 1 or nx > n or ny > n:
        continue
    
    x, y = nx, ny
    
print(x, y)

 

์˜ˆ์ œ 2 - ์‹œ๊ฐ

 

์ •์ˆ˜ N์ด ์ž…๋ ฅ๋˜๋ฉด 00์‹œ 00๋ถ„ 00์ดˆ๋ถ€ํ„ฐ N์‹œ 59๋ถ„ 59์ดˆ๊นŒ์ง€์˜ ๋ชจ๋“  ์‹œ๊ฐ ์ค‘์—์„œ 3์ด ํ•˜๋‚˜๋ผ๋„ ํฌํ•จ๋˜๋Š” ๋ชจ๋“  ๊ฒฝ์šฐ์˜ ์ˆ˜๋ฅผ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ์˜ˆ๋ฅผ ๋“ค์–ด 1์„ ์ž…๋ ฅํ–ˆ์„ ๋•Œ ๋‹ค์Œ์€ 3์ด ํ•˜๋‚˜๋ผ๋„ ํฌํ•จ๋˜์–ด ์žˆ์œผ๋ฏ€๋กœ ์„ธ์–ด์•ผ ํ•˜๋Š” ์‹œ๊ฐ์ด๋‹ค.

  • 00์‹œ 00๋ถ„ 03์ดˆ
  • 00์‹œ 13๋ถ„ 30์ดˆ

๋ฐ˜๋ฉด์— ๋‹ค์Œ์€ 3์ด ํ•˜๋‚˜๋„ ํฌํ•จ๋˜์–ด ์žˆ์ง€ ์•Š์œผ๋ฏ€๋กœ ์„ธ๋ฉด ์•ˆ ๋˜๋Š” ์‹œ๊ฐ์ด๋‹ค.

  • 00์‹œ 02๋ถ„ 55์ดˆ
  • 01์‹œ 27๋ถ„ 45์ดˆ
  • ์ฒซ์งธ ์ค„์— ์ •์ˆ˜ N์ด ์ž…๋ ฅ๋œ๋‹ค. (0 ≤ N ≤ 23)
  • 00์‹œ 00๋ถ„ 00์ดˆ๋ถ€ํ„ฐ N์‹œ 59๋ถ„ 59์ดˆ๊นŒ์ง€์˜ ๋ชจ๋“  ์‹œ๊ฐ ์ค‘์—์„œ 3์ด ํ•˜๋‚˜๋ผ๋„ ํฌํ•จ๋˜๋Š” ๋ชจ๋“  ๊ฒฝ์šฐ์˜ ์ˆ˜๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.
n = int(input())

cnt = 0

for i in range(n+1):
    for j in range(60):
        for k in range(60):
	# ์‹œ๊ฐ์„ ๋ฌธ์ž์—ด๋กœ ๋ฐ”๊พผ ํ›„ '3'์ด ํฌํ•จ๋˜์—ˆ๋Š”์ง€ ํ™•์ธ
            if '3' in str(i) + str(j) + str(k):
                cnt += 1
                
print(cnt)

 

 

์™•์‹ค์˜ ๋‚˜์ดํŠธ

# ํ˜„์žฌ ๋‚˜์ดํŠธ์˜ ์œ„์น˜ ์ž…๋ ฅ๋ฐ›๊ธฐ
input_data = input()
row = int(input_data[1])
column = int(ord(input_data[0])) - int(ord('a'))+1

# ๋‚˜์ดํŠธ๊ฐ€ ์ด๋™ํ•  ์ˆ˜ ์žˆ๋Š” 8๊ฐ€์ง€ ๋ฐฉํ–ฅ ์ •์˜
steps = [(-2,-1), (-1,-2), (1, -2), (2, -1), (2, 1), (1, 2), (-1, 2), (-2, 1)]

# 8๊ฐ€์ง€ ๋ฐฉํ–ฅ์— ๋Œ€ํ•˜์—ฌ ๊ฐ ์œ„์น˜๋กœ ์ด๋™์ด ๊ฐ€๋Šฅํ•œ์ง€ ํ™•์ธ
result = 0
for step in steps:
    # ์ด๋™ํ•˜๊ณ ์ž ํ•˜๋Š” ์œ„์น˜ ํ™•์ธ
    next_row = row + step[0]
    next_column = column + step[1]
    # ํ•ด๋‹น ์œ„์น˜๋กœ ์ด๋™์ด ๊ฐ€๋Šฅํ•˜๋‹ค๋ฉด ์นด์šดํŠธ ์ฆ๊ฐ€
    if next_row >= 1 and next_row <= 8 and next_column >= 1 and next_column <= 8:
        result += 1

 print(result)

 

๊ฒŒ์ž„ ๊ฐœ๋ฐœ

# N, M์„ ๊ณต๋ฐฑ์„ ๊ธฐ์ค€์œผ๋กœ ๊ตฌ๋ถ„ํ•˜์—ฌ ์ž…๋ ฅ๋ฐ›๊ธฐ
n, m = map(int, input().split())

# ๋ฐฉ๋ฌธํ•œ ์œ„์น˜๋ฅผ ์ €์žฅํ•˜๊ธฐ ์œ„ํ•œ ๋งต์„ ์ƒ์„ฑํ•˜์—ฌ 0์œผ๋กœ ์ดˆ๊ธฐํ™”
d = [[0] * m for _ in range(n)]
# ํ˜„์žฌ ์บ๋ฆญํ„ฐ์˜ X ์ขŒํ‘œ, Y ์ขŒํ‘œ, ๋ฐฉํ–ฅ์„ ์ž…๋ ฅ๋ฐ›๊ธฐ
x, y, direction = map(int, input().split())
d[x][y] = 1 # ํ˜„์žฌ ์ขŒํ‘œ ๋ฐฉ๋ฌธ ์ฒ˜๋ฆฌ

# ์ „์ฒด ๋งต ์ •๋ณด๋ฅผ ์ž…๋ ฅ๋ฐ›๊ธฐ
array = []
for i in range(n):
    array.append(list(map(int, input().split())))

# ๋ถ, ๋™, ๋‚จ, ์„œ ๋ฐฉํ–ฅ ์ •์˜
dx = [-1, 0, 1, 0]
dy = [0, 1, 0, -1]

# ์™ผ์ชฝ์œผ๋กœ ํšŒ์ „
def turn_left():
    global direction
    direction -= 1
    if direction == -1:
        direction = 3

# ์‹œ๋ฎฌ๋ ˆ์ด์…˜ ์‹œ์ž‘
count = 1
turn_time = 0
while True:
    # ์™ผ์ชฝ์œผ๋กœ ํšŒ์ „
    turn_left()
    nx = x + dx[direction]
    ny = y + dy[direction]
    # ํšŒ์ „ํ•œ ์ดํ›„ ์ •๋ฉด์— ๊ฐ€๋ณด์ง€ ์•Š์€ ์นธ์ด ์กด์žฌํ•˜๋Š” ๊ฒฝ์šฐ ์ด๋™
    if d[nx][ny] == 0 and array[nx][ny] == 0:
        d[nx][ny] = 1
        x = nx
        y = ny
        count += 1
        turn_time = 0
        continue
    # ํšŒ์ „ํ•œ ์ดํ›„ ์ •๋ฉด์— ๊ฐ€๋ณด์ง€ ์•Š์€ ์นธ์ด ์—†๊ฑฐ๋‚˜ ๋ฐ”๋‹ค์ธ ๊ฒฝ์šฐ
    else:
        turn_time += 1
    # ๋„ค ๋ฐฉํ–ฅ ๋ชจ๋‘ ๊ฐˆ ์ˆ˜ ์—†๋Š” ๊ฒฝ์šฐ
    if turn_time == 4:
        nx = x - dx[direction]
        ny = y - dy[direction]
        # ๋’ค๋กœ ๊ฐˆ ์ˆ˜ ์žˆ๋‹ค๋ฉด ์ด๋™ํ•˜๊ธฐ
        if array[nx][ny] == 0:
            x = nx
            y = ny
        # ๋’ค๊ฐ€ ๋ฐ”๋‹ค๋กœ ๋ง‰ํ˜€์žˆ๋Š” ๊ฒฝ์šฐ
        else:
            break
        turn_time = 0

# ์ •๋‹ต ์ถœ๋ ฅ
print(count)