๐ 1946 | ์๋ฆฌ์ผ ๋ฒํธ
https://www.acmicpc.net/problem/1946
๐ก Solution
- ๋จผ์ ์๋ฅ ์ฑ์ ๊ณผ ๋ฉด์ ์ฑ์ ์ ๋ชจ๋ ์ ๋ ฅ ๋ฐ์ listํํ๋ค.
- ์๋ฅ ์ฑ์ ์ ๊ธฐ์ค์ผ๋ก ์ ๋ ฌํ๋ค.
- ๋ณธ์ธ๋ณด๋ค ์๋ฅ ์ฑ์ ์ด ์ข์ ์ฌ๋๋ค ์ค ๊ฐ์ฅ ์ข์ ๋ฉด์ ์ฑ์ ๋ณด๋ค ๋ฉด์ ์ฑ์ ์ด ์ข์ผ๋ฉด ํฉ๊ฒฉ์ด๋ค.
- ์ด ๋, ์๋ฅ ์ฑ์ ์ด 1๋ฑ์ธ ์ฌ๋์ ์ ๋ ๋ค๋ฅธ ์ง์์๋ณด๋ค ๋ชจ๋ ์ฑ์ ์ด ๋จ์ด์ง ์ ์์ผ๋ฏ๋ก ๋ฌด์กฐ๊ฑด ์ ๋ฐ์ด๋ค.
import sys
input = sys.stdin.readline
def find_passed_count(n) :
count = 1
candidates = []
for i in range(n) :
document_score, interview_score = map(int, input().split())
candidates.append((document_score, interview_score))
candidates.sort(key = lambda x: (x[0]))
threshold = candidates[0][1]
for i in range(1, n) :
if threshold > candidates[i][1] :
count += 1
threshold = candidates[i][1]
return count
t = int(input().rstrip())
while t :
n = int(input().rstrip())
print(find_passed_count(n))
t -= 1
๐ Note
์ฒ์์ ๋ค์๊ณผ ๊ฐ์ด ์ด์ค for๋ฌธ์ ์ฌ์ฉํ๋๋ ์๊ฐ๋ณต์ก๋๊ฐ O(N^2)์ด ๋์์ ์๊ฐ ์ด๊ณผ๊ฐ ๋ด๋ค.
์ฌ๋งํ๋ฉด ์ด์ค for๋ฌธ์ ์ฌ์ฉํ์ง ์์ ๊ฒ !
import sys input = sys.stdin.readline def find_passed_count(n) : count = n candidates = [] for i in range(n) : document_score, interview_score = map(int, input().split()) candidates.append((document_score, interview_score)) candidates.sort(key = lambda x: (x[0])) for i in range(n) : for j in range(i) : if candidates[i][1] > candidates[j][1] : count -= 1 break return count t = int(input().rstrip()) while t : n = int(input().rstrip()) print(find_passed_count(n)) t -= 1โ
'์๊ณ ๋ฆฌ์ฆ ๐ฉ๐ปโ๐ป > ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[BAEKJOON] 9375 | ํจ์ ์ ์ ํด๋น (2) | 2024.12.19 |
---|---|
[BAEKJOON] 14425 | ๋ฌธ์์ด ์งํฉ (0) | 2024.12.19 |
[BAEKJOON] 1431 | ์๋ฆฌ์ผ ๋ฒํธ (0) | 2024.12.18 |
[BAEKJOON] 19636 | ์์ ์๋ฎฌ๋ ์ด์ (0) | 2024.12.18 |
[BAEKJOON] 10820 | ๋ฌธ์์ด ๋ถ์ (0) | 2024.11.28 |