-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
10-SeongHoonC #38
10-SeongHoonC #38
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
νμ΄μ¬μ μ΄λ κ² sort ν¨μμμ μ λ ¬μ μ°μ μμλ₯Ό μ§μ ν μ μλ΅λλ€.
νμ΄ μ λ΄€μ΄μ!
import sys
input = sys.stdin.readline
N = int(input())
lst = []
answer = 1
for i in range(N):
start, end = map(int, input().split())
lst.append([start, end])
lst.sort(key=lambda x: (x[1], x[0]))
cur = lst[0]
for _next in lst[1:]:
if cur[1] > _next[0]:
continue
answer += 1
cur = _next
print(answer)
νλ λ°°μκ°λλ€~ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ²μμ μ΄λ»κ² μ΅λ νμ μλ₯Ό μ‘μ μ μλμ§ μκ°ν΄λ΄κΈ° μ΄λ €μ΄ λ¬Έμ μΈ κ±° κ°λ€μ! μ²μμ κ³ λ―Όνλ€κ° μ±ν λ μ²λΌ λλλ μκ°μ΄ μμνλ μκ°λ³΄λ€ μκ±°λ κ°μΌλ©΄ λ€μ νμλ₯Ό μ‘μΌλ©΄ λλ€λ μκ°μ ν΄λ΄λ λ° μκ°μ΄ μ‘°κΈ κ±Έλ¦° κ±° κ°μ΄λ€ γ γ
N = int(input())
time_table = []
for _ in range(N):
start_time, end_time = map(int, input().split())
time_table.append([start_time, end_time])
time_table.sort(key=lambda item : (item[1], item[0]))
answer =1
current = time_table[0]
for time in time_table[1:] :
if (current[1] > time[0]) :
continue
answer +=1
current = time
print(answer)
μ λ λ€λ₯ΈλΆλ€κ³Ό μ½λλ λΉμ·νκ² λμ€λ€μ!! κ·Έλ¦¬κ³ μ΅κ·Όμ λΉμ·νλ λ¬Έμ μΈ from collections import deque
n = int(input())
result = []
for i in range(n):
result.append(list(map(int, input().split())))
result.sort(key=lambda x:(x[1],x[0]))
room = result[0][1]
count = 1
for i in range(1,n):
if result[i][0] >= room:
room = result[i][1]
count += 1
print(count) |
π λ¬Έμ λ§ν¬
νμμ€ λ°°μ
ν κ°μ νμμ€μ΄ μλλ° μ΄λ₯Ό μ¬μ©νκ³ μ νλ Nκ°μ νμμ λνμ¬ νμμ€ μ¬μ©νλ₯Ό λ§λ€λ €κ³ νλ€. κ° νμ Iμ λν΄ μμμκ°κ³Ό λλλ μκ°μ΄ μ£Όμ΄μ Έ μκ³ , κ° νμκ° κ²ΉμΉμ§ μκ² νλ©΄μ νμμ€μ μ¬μ©ν μ μλ νμμ μ΅λ κ°μλ₯Ό μ°Ύμ보μ. λ¨, νμλ νλ² μμνλ©΄ μ€κ°μ μ€λ¨λ μ μμΌλ©° ν νμκ° λλλ κ²κ³Ό λμμ λ€μ νμκ° μμλ μ μλ€. νμμ μμμκ°κ³Ό λλλ μκ°μ΄ κ°μ μλ μλ€. μ΄ κ²½μ°μλ μμνμλ§μ λλλ κ²μΌλ‘ μκ°νλ©΄ λλ€.
βοΈ μμλ μκ°
20λΆ
β¨ μλ μ½λ
μ΄λ €μΈ μ€ μμλλ° ν΄κ²° λ°©λ²μ΄ 빨리 λ μ¬λΌμ νλ°© μ»· νλ€μ!
λ€μ νμλ₯Ό μμνλ €λ©΄ μ΄μ νμκ° λλλ μκ° μ΄νμ΄λ€..
μμ, λμ΄ κ°μ νμκ° μμ μ μμΌλ©° μ΄λ νμκ° μμνμλ§μ λλλ κ²μ΄λ€.
μμ)
μ λ ₯ :
5
1 4
2 4
3 5
4 4
5 7
μ΄λΌλ©΄ μ λ ¬λ κ²°κ³Όλ λ€μκ³Ό κ°λ€.
(1, 4) (2, 4), (4, 4), (3, 5), (5, 7)
λ΅μ 3μ΄ λλ€.
π μλ‘κ² μκ²λ λ΄μ©
sortWith μ μ¬μ©ν΄ μ¬λ¬κ°μ§ 쑰건μΌλ‘ μ λ ¬μ΄ κ°λ₯νλ€!