Part3.6_이분탐색(결정알고리즘)&그리디 알고리즘_씨름 선수(그리디)

Eugenius1st·2022년 1월 13일
0

Python_algorithm

목록 보기
12/83

내가 생각한 코드

근데 약간 힌트 봐버렸다..
sort 한 후 막히길래..

!!반대로 sort 하는 것이 주요 끼 뽀인뜨!!!
이제 x[0] 부터 x[n] 까지 뒤에 오는 값보다 크면 된다...
170 72 >> 얜 젤 뚱뚱해서 괜찮
180 70 >> 얘가 170 보다 큰지 확인
172 67 >> 얘가 max인 180보다 큰지 확인
183 65 >> 얘가 max인 180보다 큰지 확인
181 60 >> 얘가 max인 183보다 큰지 확인

#1. Alt+W+N 입력하고 Alt+W+V :

import sys
sys.stdin = open("input.txt", "rt")

n= int(input())
people = []

for _ in range(n):
    t, w = map(int,input().split())
    people.append((t,w))

people.sort(key = lambda x : (x[1],x[0]))
people.reverse()

maxT = 0
cnt = 0

for t, w in people:
    if t>maxT:
        maxT=t
        cnt+=1
print(cnt)

100..

선생님 코드

#1. Alt+W+N 입력하고 Alt+W+V :

import sys
sys.stdin = open("input.txt", "rt")

n= int(input())
body = []

for _ in range(n):
    a, b = map(int,input().split())
    body.append((a,b))

body.sort(reverse=True)

largest = 0
cnt = 0
for x, y in body:
    if y>largest:
        largest=y
        cnt+=1
print(cnt)
profile
최강 프론트엔드 개발자가 되고싶은 안유진 입니다

0개의 댓글