์ƒˆ์†Œ์‹

๐Ÿงฎ PS

๋ฐฑ์ค€(boj) 10825 ํŒŒ์ด์ฌ - ๊ตญ์˜์ˆ˜

  • -

๋ฌธ์ œ๋งํฌ : https://www.acmicpc.net/problem/10825

 

10825๋ฒˆ: ๊ตญ์˜์ˆ˜

์ฒซ์งธ ์ค„์— ๋„ํ˜„์ด๋„ค ๋ฐ˜์˜ ํ•™์ƒ์˜ ์ˆ˜ N (1 ≤ N ≤ 100,000)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„๋ถ€ํ„ฐ ํ•œ ์ค„์— ํ•˜๋‚˜์”ฉ ๊ฐ ํ•™์ƒ์˜ ์ด๋ฆ„, ๊ตญ์–ด, ์˜์–ด, ์ˆ˜ํ•™ ์ ์ˆ˜๊ฐ€ ๊ณต๋ฐฑ์œผ๋กœ ๊ตฌ๋ถ„ํ•ด ์ฃผ์–ด์ง„๋‹ค. ์ ์ˆ˜๋Š” 1๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , 100๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ž์—ฐ์ˆ˜์ด๋‹ค. ์ด๋ฆ„์€ ์•ŒํŒŒ๋ฒณ ๋Œ€์†Œ๋ฌธ์ž๋กœ ์ด๋ฃจ์–ด์ง„ ๋ฌธ์ž์—ด์ด๊ณ , ๊ธธ์ด๋Š” 10์ž๋ฆฌ๋ฅผ ๋„˜์ง€ ์•Š๋Š”๋‹ค.

www.acmicpc.net

 

๋ฆฌ์ŠคํŠธ์˜ ์š”์†Œ ์ธ๋ฑ์Šค๋ฅด ๊ธฐ์ค€์œผ๋กœ sortํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์•Œ์•„์•ผ ํ–ˆ๋‹ค.

arr.sort(key=lambda x: x[0] )    -> x[0]๋ฒˆ ๊ธฐ์ค€์œผ๋กœ sort

*๋‚ด ์ฝ”๋“œ

N = int(input()) ; arr = []

for _ in range(N):
    arr.append(list(map(str,input().split())))
arr.sort(key=lambda x : str(x[0])) ##4
arr.sort(key=lambda x:int(x[3]), reverse=True) ##3
arr.sort(key = lambda x : int(x[2])) ## 2
arr.sort(key = lambda x: int(x[1]), reverse = True)##1


for i in arr :
    print(i[0])

 

arr.sort๋ฅผ 4๋ฒˆ์ด๋‚˜ ์‚ฌ์šฉํ–ˆ๋‹ค. ์ด๋ ‡๊ฒŒ ์ผ์ผ์ด ์‚ฌ์šฉํ–ˆ์„๋•Œ๋Š” ๋ฌธ์ œ์—์„œ ์ œ์‹œํ•œ ์ •๋ ฌ์ˆœ์„œ์™€, ์‹ค์ œ๋กœ ์†ŒํŒ…ํ•˜๋Š” ์ˆœ์„œ๋ฅผ ๋ฐ˜๋Œ€๋กœ ํ•ด์•ผํ–ˆ๋‹ค. (๋ฌธ์ œ์—์„œ ์ œ์‹œํ•œ 1์ˆœ์œ„ ๊ธฐ์ค€์„ ๋งˆ์ง€๋ง‰ ์ˆœ์„œ๋กœ ์ฝ”๋”ฉํ•ด์•ผ, 1์ˆœ์œ„๋กœ ์ ์šฉ๋˜๊ธฐ ๋•Œ๋ฌธ)

๋‹ค๋ฅธ์‚ฌ๋žŒ์˜ ์ฝ”๋“œ๋ฅผ ๋ณด๋‹ˆ, ์ด๋Ÿฐ์‹์œผ๋กœ ์ข€ ๋” ๊น”๋”ํ•˜๊ฒŒ ์‚ฌ์šฉํ–ˆ๋‹ค.

*๋ชจ๋ฒ” ์ฝ”๋“œ

N = int(input()) ; arr = []

for _ in range(N):
    a,b,c,d = list(map(str,input().split()))
    arr.append( [a, int(b),int(c),int(d)])

arr.sort(key = lambda x : (-x[1] , x[2],-x[3],x[0]) )

for i in arr :
    print(i[0])

 

 

sort(reverse=True)๋ฅผ ๋žŒ๋‹ค์‹์—์„œ, ๋งˆ์ด๋„ˆ์Šค๋ฅผ ๋ถ™์ด๋Š” ๋ฐฉ๋ฒ•์œผ๋กœ ์งง๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค. 

์ด๋ ‡๊ฒŒ ํ•˜๋‹ˆ ๋ฌธ์ œ์—์„œ ์ œ์‹œํ•˜๋Š” ์ •๋ ฌ์ˆœ์„œ์™€, ์ฝ”๋”ฉํ•˜๋Š” ์ •๋ ฌ์ˆœ์„œ๋„ ์ผ์น˜ํ•˜๊ณ  ์ข€ ๋” ๊ฐ€๋…์„ฑ๋„ ์ข‹์•˜๋‹ค.

arr.sort(key = lambda x : x[1], reverse=True) == arr.sort(key=lambda x : -x[1])

Contents

ํฌ์ŠคํŒ… ์ฃผ์†Œ๋ฅผ ๋ณต์‚ฌํ–ˆ์Šต๋‹ˆ๋‹ค

์ด ๊ธ€์ด ๋„์›€์ด ๋˜์—ˆ๋‹ค๋ฉด ๊ณต๊ฐ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.