Skip to content
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

Merged
merged 3 commits into from
Feb 25, 2024
Merged

10-SeongHoonC #38

merged 3 commits into from
Feb 25, 2024

Conversation

SeongHoonC
Copy link
Collaborator

@SeongHoonC SeongHoonC commented Feb 23, 2024

πŸ”— 문제 링크

νšŒμ˜μ‹€ λ°°μ •

ν•œ 개의 νšŒμ˜μ‹€μ΄ μžˆλŠ”λ° 이λ₯Ό μ‚¬μš©ν•˜κ³ μž ν•˜λŠ” N개의 νšŒμ˜μ— λŒ€ν•˜μ—¬ νšŒμ˜μ‹€ μ‚¬μš©ν‘œλ₯Ό λ§Œλ“€λ €κ³  ν•œλ‹€. 각 회의 I에 λŒ€ν•΄ μ‹œμž‘μ‹œκ°„κ³Ό λλ‚˜λŠ” μ‹œκ°„μ΄ μ£Όμ–΄μ Έ 있고, 각 νšŒμ˜κ°€ κ²ΉμΉ˜μ§€ μ•Šκ²Œ ν•˜λ©΄μ„œ νšŒμ˜μ‹€μ„ μ‚¬μš©ν•  수 μžˆλŠ” 회의의 μ΅œλŒ€ 개수λ₯Ό μ°Ύμ•„λ³΄μž. 단, νšŒμ˜λŠ” ν•œλ²ˆ μ‹œμž‘ν•˜λ©΄ 쀑간에 쀑단될 수 μ—†μœΌλ©° ν•œ νšŒμ˜κ°€ λλ‚˜λŠ” 것과 λ™μ‹œμ— λ‹€μŒ νšŒμ˜κ°€ μ‹œμž‘λ  수 μžˆλ‹€. 회의의 μ‹œμž‘μ‹œκ°„κ³Ό λλ‚˜λŠ” μ‹œκ°„μ΄ 같을 μˆ˜λ„ μžˆλ‹€. 이 κ²½μš°μ—λŠ” μ‹œμž‘ν•˜μžλ§ˆμž λλ‚˜λŠ” κ²ƒμœΌλ‘œ μƒκ°ν•˜λ©΄ λœλ‹€.

βœ”οΈ μ†Œμš”λœ μ‹œκ°„

20λΆ„

✨ μˆ˜λ„ μ½”λ“œ

μ–΄λ €μšΈ 쀄 μ•Œμ•˜λŠ”λ° ν•΄κ²° 방법이 빨리 λ– μ˜¬λΌμ„œ ν•œλ°© μ»· ν–ˆλ„€μš”!

λ‹€μŒ 회의λ₯Ό μ‹œμž‘ν•˜λ €λ©΄ 이전 νšŒμ˜κ°€ λλ‚˜λŠ” μ‹œκ°„ 이후이닀..
μ‹œμž‘, 끝이 같은 νšŒμ˜κ°€ μžˆμ„ 수 있으며 μ΄λŠ” νšŒμ˜κ°€ μ‹œμž‘ν•˜μžλ§ˆμž λλ‚˜λŠ” 것이닀.

  1. λλ‚˜λŠ” μ‹œκ°„μ„ κΈ°μ€€μœΌλ‘œ μ •λ ¬
  2. μ •λ ¬λœ νšŒμ˜μ—μ„œ 첫번째 회의λ₯Ό μ‹œμž‘ν•˜κ³  κ·Έ λ‹€μŒ νšŒμ˜λŠ” 이전 회의 λ‹€μŒ μ‹œκ°„ 쀑 λλ‚˜λŠ” μ‹œκ°„μ΄ κ°€μž₯ μž‘μ€ 것을 골라 μ‹œμž‘
  3. μ‹œμž‘κ³Ό 끝이 같은 κ²½μš°λŠ” κ·Έ 수만큼 +1

μ˜ˆμ‹œ)
μž…λ ₯ :
5
1 4
2 4
3 5
4 4
5 7

이라면 μ •λ ¬λœ κ²°κ³ΌλŠ” λ‹€μŒκ³Ό κ°™λ‹€.
(1, 4) (2, 4), (4, 4), (3, 5), (5, 7)

  1. (1, 4) 회의λ₯Ό μ‹œμž‘ν•œλ‹€. +1
  2. (2, 4) λŠ” (1,4)와 λλ‚˜λŠ” μ‹œκ°„μ΄ κ°™μ•„μ„œ 패슀
  3. (4, 4) λŠ” μ‹œμž‘κ³Ό 끝이 κ°™μ•„μ„œ 회의λ₯Ό μ‹œμž‘ν•œλ‹€. +1
  4. (3, 5) λŠ” μ‹œμž‘ 3이 이전 νšŒμ˜κ°€ λλ‚˜λŠ” μ‹œκ°„ 4보닀 μž‘μœΌλ―€λ‘œ 패슀
  5. (5, 7) μ‹œμž‘ 5κ°€ 이전 νšŒμ˜κ°€ λλ‚˜λŠ” μ‹œκ°„ 4 보닀 크기 λ•Œλ¬Έμ— 회의λ₯Ό μ‹œμž‘ν•œλ‹€. +1

닡은 3이 λœλ‹€.

πŸ“š μƒˆλ‘­κ²Œ μ•Œκ²Œλœ λ‚΄μš©

sortWith 을 μ‚¬μš©ν•΄ μ—¬λŸ¬κ°€μ§€ 쑰건으둜 정렬이 κ°€λŠ₯ν•˜λ‹€!

meets.sortWith(compareBy({ it.second }, { it.first }))

Copy link
Member

@fnzksxl fnzksxl left a 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)

@wkdghdwns199
Copy link
Collaborator

νŒŒμ΄μ¬μ€ μ΄λ ‡κ²Œ 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)

ν•˜λ‚˜ λ°°μ›Œκ°‘λ‹ˆλ‹€~

Copy link
Collaborator

@wkdghdwns199 wkdghdwns199 left a 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)

@alstjr7437
Copy link
Member

alstjr7437 commented Feb 25, 2024

저도 λ‹€λ₯ΈλΆ„λ“€κ³Ό μ½”λ“œλŠ” λΉ„μŠ·ν•˜κ²Œ λ‚˜μ˜€λ„€μš”!!
λ”°λ‘œ 정렬해두고 1을 λ„£κ³  λͺ¨λ‘ λŒλ©΄μ„œ λλ‚˜λŠ” μ‹œκ°„μ΄ μ‹œμž‘ μ‹œκ°„λ³΄λ‹€ 크면 room을 κ°±μ‹ ν•΄μ£ΌλŠ” μ‹μœΌλ‘œ ν–ˆμŠ΅λ‹ˆλ‹€!

그리고 μ΅œκ·Όμ— λΉ„μŠ·ν–ˆλ˜ 문제인
κ°•μ˜μ‹€ 배정을 ν’€μ–΄μ„œ μ‰½κ²Œ ν’€λ Έλ„€μš”!!

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants