๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm/๋ฐฑ์ค€(BOJ)

[ ํŒŒ์ด์ฌ(python) ] ๋ฐฑ์ค€ 7568 - ๋ฉ์น˜

by YWTechIT 2021. 5. 18.
728x90

๐Ÿ“ ๋ฐฑ์ค€ 7568 - ๋ฉ์น˜

๋ฐฑ์ค€ 7568 - ๋ฉ์น˜


โšก๏ธ ๋‚˜์˜ ํ’€์ด

์–ธ์  ๊ฐ€ ๋‹จ๊ณ„๋ณ„ ํ’€์ด์—์„œ ํ•œ๋ฒˆ ๋ดค์—ˆ๋Š”๋ฐ, ์–ด๋–ป๊ฒŒ ํ’€์–ด์•ผ ํ• ์ง€ ๋ชฐ๋ผ ๋„˜๊ฒผ์—ˆ๋Š”๋ฐ ์ด๋ฒˆ์—” ํ’€์—ˆ๋‹ค.

 

์ด ๋ฌธ์ œ์˜ ๊ฐ€์žฅ ํ•ต์‹ฌ ๋ฌธ์žฅ์€ ๊ฐ ์‚ฌ๋žŒ์˜ ๋ฉ์น˜ ๋“ฑ์ˆ˜๋Š” ์ž์‹ ๋ณด๋‹ค ๋” ํฐ ๋ฉ์น˜์˜ ์‚ฌ๋žŒ์˜ ์ˆ˜๋กœ ์ •ํ•ด์ง„๋‹ค.์ด๋‹ค. ์ด์ค‘ ๋ฐ˜๋ณต๋ฌธ์˜ ๋ฒ”์œ„๋Š” A-B, A-C, A-D, A-E / B-A, B-C, B-D, B-E / C-A, C-B, C-D, C-E / E-A, E-B, E-C, E-D ์ฒ˜๋Ÿผ ๋ชจ๋“  ๊ฒฝ์šฐ์˜ ์ˆ˜๋ฅผ ๋น„๊ตํ•  ์ˆ˜ ์žˆ๊ฒŒ ์„ ์–ธํ•ด์•ผ ํ•œ๋‹ค.

 

A-B๋‚˜ B-A๋‚˜ ๊ฐ™์€๊ฑฐ์•„๋‹Œ๊ฐ€?! ๋ผ๊ณ  ์ƒ๊ฐํ•  ์ˆ˜๋„ ์žˆ์ง€๋งŒ, ๊ฐ๊ฐ์˜ ์ผ€์ด์Šค์—์„œ ๋ฉ์น˜ ๋“ฑ์ˆ˜๋ฅผ ์…€ ๋•Œ ๋‚˜๋ฅผ ์ œ์™ธํ•œ ๋ชจ๋“  ์‚ฌ๋žŒ์˜ ๋ฉ์น˜๋ฅผ ๋น„๊ตํ•ด์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๊ฐ™์ง€ ์•Š๋‹ค.

 

  1. ์ž์‹ ์„ ํฌํ•จํ•œ ๋ชจ๋“  ๊ฒฝ์šฐ์˜ ์ˆ˜๋ฅผ ์กฐ์‚ฌํ•œ๋‹ค.(๋ฐ˜๋ณต๋ฌธ์˜ ๋ฒ”์œ„ ์„ค์ •์˜ ํŽธ์˜์„ฑ ์œ„ํ•ด ์ž์‹ ๋„ ํฌํ•จ์‹œ์ผฐ๋‹ค. ์ž์‹ ๋ผ๋ฆฌ๋Š” ๋Œ€์†Œ๊ด€๊ณ„๊ฐ€ ์„ฑ๋ฆฝ๋˜์ง€ ์•Š๋Š”๋‹ค.)
  2. 1๋“ฑ๋ณด๋‹ค ๋†’์€ ๋“ฑ์ˆ˜(0๋“ฑ์€ ์—†๋‹ค.)๊ฐ€ ์—†์œผ๋ฏ€๋กœ ๋“ฑ์ˆ˜(prize)์˜ ์ดˆ๊ธฐ๊ฐ’์€ 1์ด๋‹ค.
  3. ํ˜„์žฌ ๊ฐ’๊ณผ ๋‹ค์Œ๊ฐ’์„ ๋น„๊ตํ•ด์„œ ์ž์‹ ๋ณด๋‹ค ๋” ํฐ ์‚ฌ๋žŒ์ด ์žˆ๋‹ค๋ฉด prize๋ฅผ 1 ์ฆ๊ฐ€์‹œํ‚จ๋‹ค.(์ˆœ์œ„๊ฐ€ ๋‚ด๋ ค๊ฐ„๋‹ค๋Š” ์˜๋ฏธ)

 

์ •๋‹ต ํŒ์ •์„ ๋ฐ›์•˜๋Š”๋ฐ, ๋‹ค๋ฅธ ์‚ฌ๋žŒ์˜ ์ฝ”๋“œ์—์„œ๋Š” ๋‚˜์ฒ˜๋Ÿผ 2์ค‘ ๋ฐ˜๋ณต๋ฌธ ์ค‘๊ฐ„์— prize = 1์„ ์‚ฌ์šฉํ•˜์ง€์•Š๊ณ , prize=[1]*n์œผ๋กœ ์ดˆ๊ธฐํ™”๋ฅผ ํ•ด๋†“๊ณ ๋‚˜์„œ ๋‚˜์ค‘์— ํ•ด๋‹น ์ธ๋ฑ์Šค๋งŒ 1 ์ฆ๊ฐ€ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ–ˆ๋‹ค. ๊ฐ€๋…์„ฑ์ด ๊ดœ์ฐฎ์€ ์ฝ”๋“œ์˜€๊ณ , ์ธ๋ฑ์Šค๋งˆ๋‹ค cnt๋ฅผ ์ฆ๊ฐ€ํ•˜๋Š” ๋ฌธ์ œ๋ฅผ ํ’€ ๋•Œ ์‚ฌ์šฉํ•˜๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™๋‹ค.

 

n = int(input())
people = [tuple(map(int, input().split())) for _ in range(n)]
result = []

# ๋‚˜์˜ ์ฝ”๋“œ
for i in range(n):
    prize = 1
    for j in range(n):
        if people[i][0] < people[j][0] and people[i][1] < people[j][1]:
            prize += 1
    result.append(prize)
print(' '.join(map(str, result)))

# ๋‹ค๋ฅธ์‚ฌ๋žŒ์˜ ์ฝ”๋“œ
prize = [1] * n

for i in range(n):
    for j in range(n):
        if people[i][0] < people[j][0] and people[i][1] < people[j][1]:
            prize[i] += 1
print(' '.join(map(str, result)))
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€