Algorithm Greedy 2

๊ณฑํ•˜๊ธฐ ํ˜น์€ ๋”ํ•˜๊ธฐ

๊ฐ ์ž๋ฆฌ ์ˆซ์ž(0 ~ 9)๋กœ๋งŒ ์ด๋ฃจ์–ด์ง„ ๋ฌธ์ž์—ด S๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, ์™ผ์ชฝ ๋ถ€ํ„ฐ ์˜ค๋ฅธ์ชฝ ์œผ๋กœ ํ•˜๋‚˜์”ฉ ๋ชจ๋“  ์ˆซ์ž๋ฅผ ํ™•์ธํ•˜๋ฉฐ ์ˆซ์ž ์‚ฌ์ด์— x, +๋ฅผ ๋จผ์ € ๊ณ„์‚ฐํ•˜๋Š” ๋งŒ๋“ค์–ด์งˆ ์ˆ˜ ์žˆ๋Š” ๊ฐ€์žฅ ํฐ ์ˆ˜๋ฅผ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ

In(S), Out(n)

numbers = input()
n = int(numbers[0])

for i in range(1, len(numbers)):
    num = int(numbers[i])
    
    if num <= 1 or n <= 1 :
        n += num
    else:
        n *= num
print(n)        
02984
576

๋ชจํ—˜๊ฐ€ ๊ธธ๋“œ

๊ณตํฌ๋„๊ฐ€ X์ธ ๋ชจํ—˜๊ฐ€๋Š” ๋ฐ˜๋“œ์‹œ X๋ช… ์ด์ƒ์œผ๋กœ ๊ตฌ์„ฑํ•œ ๋ชจํ—˜๊ฐ€ ๊ทธ๋ฃน์— ์ฐธ์—ฌ ํ•ด์•ผํ•จ

N๋ช…์˜ ๋ชจํ—˜๊ฐ€์— ๋Œ€ํ•œ ์ •๋ณด๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, ์—ฌํ–‰์„ ๋– ๋‚  ์ˆ˜ ์žˆ๋Š” ๊ทธ๋ฃน ์ˆ˜์˜ ์ตœ๋Œ“๊ฐ’์„ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ

number = int(input())
adventurer = list(map(int, input().split()))
group = 0
adventurer.sort()
temp = 0

for i in adventurer:
    temp += i
    
    if temp >= number:
        group += 1
        temp = 0
        
print(str(group))
5
2 3 1 2 2
2

์ƒํ•˜์ขŒ์šฐ

def move(x, y, size):
    for i in range(0,size):
        for j in range(0,size):
            if i == x and j == y:
                    print('(  here  )',end = ' ')
            else:
                print('(', i + 1 , ', ', j + 1 , ')',end = ' ')
        print()

#ํฌ๊ธฐ
size = int(input()) + 1

#๋ช…๋ น
com = map(str, input().split())

#ํ˜„์žฌ ์œ„์น˜
x, y = 0, 0

#๋™, ๋ถ, ์„œ, ๋‚จ
dx = [0, -1, 0, 1] 
dy = [1, 0, -1, 0] 

move_types = {'R' : 0,
              'U' : 1,
              'L' : 2,
              'D' : 3
             }

temp_y = 0
temp_x = 0

move(x, y, size)
print()

for i in com:
    print(dx[move_types[i]], ',' , dy[move_types[i]])
    temp_x = x + dx[move_types[i]]
    temp_y = y + dy[move_types[i]]
    
    if temp_x < 0 or temp_x > size or temp_y < 0 or temp_y > size:
        continue
    
    x = temp_x
    y = temp_y
    move(x, y, size)
    print()
    
print('(', x + 1, ',', y +1 , ')')
5
R R R U D D
(  here  ) ( 1 ,  2 ) ( 1 ,  3 ) ( 1 ,  4 ) ( 1 ,  5 ) ( 1 ,  6 ) 
( 2 ,  1 ) ( 2 ,  2 ) ( 2 ,  3 ) ( 2 ,  4 ) ( 2 ,  5 ) ( 2 ,  6 ) 
( 3 ,  1 ) ( 3 ,  2 ) ( 3 ,  3 ) ( 3 ,  4 ) ( 3 ,  5 ) ( 3 ,  6 ) 
( 4 ,  1 ) ( 4 ,  2 ) ( 4 ,  3 ) ( 4 ,  4 ) ( 4 ,  5 ) ( 4 ,  6 ) 
( 5 ,  1 ) ( 5 ,  2 ) ( 5 ,  3 ) ( 5 ,  4 ) ( 5 ,  5 ) ( 5 ,  6 ) 
( 6 ,  1 ) ( 6 ,  2 ) ( 6 ,  3 ) ( 6 ,  4 ) ( 6 ,  5 ) ( 6 ,  6 ) 

0 , 1
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