728x90
๋ฐ˜์‘ํ˜•

๋ฐฑ์ค€ & ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/greedy 5

[๋ฐฑ์ค€ 1541] [greedy] ์žƒ์–ด๋ฒ„๋ฆฐ ๊ด„ํ˜ธ

๐Ÿ’ป ๋ฐฑ์ค€ 1541๋ฒˆ [์žƒ์–ด๋ฒ„๋ฆฐ ๊ด„ํ˜ธ]1541๋ฒˆ: ์žƒ์–ด๋ฒ„๋ฆฐ ๊ด„ํ˜ธ์ฒซ์งธ ์ค„์— ์‹์ด ์ฃผ์–ด์ง„๋‹ค. ์‹์€ ‘0’~‘9’, ‘+’, ๊ทธ๋ฆฌ๊ณ  ‘-’๋งŒ์œผ๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๊ณ , ๊ฐ€์žฅ ์ฒ˜์Œ๊ณผ ๋งˆ์ง€๋ง‰ ๋ฌธ์ž๋Š” ์ˆซ์ž์ด๋‹ค. ๊ทธ๋ฆฌ๊ณ  ์—ฐ์†ํ•ด์„œ ๋‘ ๊ฐœ ์ด์ƒ์˜ ์—ฐ์‚ฐ์ž๊ฐ€ ๋‚˜ํƒ€๋‚˜์ง€ ์•Š๊ณ , 5์ž๋ฆฌ๋ณด๋‹ค www.acmicpc.netํ’€์ด)# ์ตœ์ข…์ œ์ถœ import re eq = input() num_lst = re.split('[+|-]',eq) stack = [] stack.append(int(num_lst[0])) i = 1 for ch in eq : if ch.isnumeric() == False : if ch == '+' : stack.append(int(stack.pop()) + int(num_lst[i])) else : stack.append(..

[๋ฐฑ์ค€ 1931] [greedy] ํšŒ์˜์‹ค ๋ฐฐ์ • โ—

๐Ÿ’ป ๋ฐฑ์ค€ 1931๋ฒˆ [ํšŒ์˜์‹ค ๋ฐฐ์ •] 1931๋ฒˆ: ํšŒ์˜์‹ค ๋ฐฐ์ • (1,4), (5,7), (8,11), (12,14) ๋ฅผ ์ด์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. www.acmicpc.net ํ’€์ด) n = int(input()) lst = sorted([list(map(int,input().split())) for _ in range(n)], key = lambda x : (x[1],x[0])) cnt = 1 cur = lst[0] for i in range(1,len(lst)) : if lst[i][0] >= cur[1] : cnt+=1 cur = lst[i] print(cnt) ๋ฉ”๋ชจ๋ฆฌ ์‹œ๊ฐ„ ์–ธ์–ด ์ฝ”๋“œ๊ธธ์ด 57248KB 4308ms Python 3 237B ๊ณผ์ •) ๋นจ๋ฆฌ ๋๋‚˜๋Š” ์‹œ๊ฐ„๋Œ€๋กœ ํšŒ์˜๋ฅผ ์ •๋ ฌํ•ด์•ผํ•œ๋‹ค๋Š” ๊ฒƒ์€ ์•Œ์•˜๋‹ค. ์ด์™ธ์— ..

[๋ฐฑ์ค€ 11047] [greedy] ๋™์ „ 0

๋ฐฑ์ค€ 11047๋ฒˆ [๋™์ „ 0] ํ’€์ด) # ์ตœ์ข…์ œ์ถœ lst = list(map(int,(input().split()))) a_lst = [int(input()) for _ in range(lst[0])] k = lst[1] cnt = 0 for i in range(len(a_lst)-1,-1,-1) : cnt += k//a_lst[i] k = k%a_lst[i] print(cnt) # ==> ๋ฉ”๋ชจ๋ฆฌ : 28776kb, ์‹œ๊ฐ„ : 76ms, ์ฝ”๋“œ๊ธธ์ด : 193B

728x90
๋ฐ˜์‘ํ˜•