Skip to content

Conversation

@YoonYn9915
Copy link
Member

@YoonYn9915 YoonYn9915 commented Apr 19, 2025

🌱WIL

이번 한 주의 소감을 작성해주세요!

  • 이번 한주는 백트래킹, 그리디, 조합 중에서 가장 기본적이고 간단한 문제를 풀어봤다. 여기저기 면접도 다니고 지원서도 쓰느라 알고리즘 공부는 잘 안하게 되는 면이 있어서 앞으로는 쉽고 빠르게 풀수 있는 간단한 문제를 위주로 풀려고 한다. 이제 이정도 문제는 힌트 안보고 빠른 시간안에 풀 수있게 되어서 알고리즘 동아리 했던 지난 9개월이 실력 향상에 많은 도움이 된 거 같다고 느낀다!

🚀주간 목표 문제 수: 3개

푼 문제


백준 #1759. 암호 만들기: 백트래킹 / 골드 5

정리한 링크: (바로가기)

🚩제출한 코드

def check_password(password):
    num_vowel = sum(1 for c in password if c in 'aeiou')
    num_consonant = len(password) - num_vowel
    return num_vowel >= 1 and num_consonant >= 2

def recursion(start, depth, password):
    if depth == L:
        if check_password(password):
            answers.append(password)
        return

    for i in range(start, len(letters)):
        recursion(i + 1, depth + 1, password + letters[i])

L, C = map(int, input().split())
letters = sorted(input().split())
answers = []

recursion(0, 0, '')

for ans in answers:
    print(ans)

백준 #13305. 주유소: 그리디 / 실버 3

정리한 링크: (바로가기)

🚩제출한 코드

import sys

inp = sys.stdin.readline

n = int(inp())

roads = list(map(int, inp().split()))
oil_prices = list(map(int, inp().split()))

# 최소 비용
answer = 0
# 현재 도시
loc = 0

while True:
    # 현재 도시보다 기름값이 적은 곳 찾기
    for i in range(loc + 1, n):
        if oil_prices[loc] > oil_prices[i] or i == n - 1:
            # 이곳까지 가기 위해 현재 도시에서 주유하면서 비용 소모
            # 현재 도시의 기름값 * i번 도시까지 가야 할 거리
            answer += oil_prices[loc] * sum(roads[loc:i])
            loc = i
            break

    if loc == n - 1:
        break

print(answer)

백준 #6603. 로또: 그리디 / 실버 2

정리한 링크: (바로가기)

🚩제출한 코드

import sys
from itertools import combinations

inp = sys.stdin.readline

while True:
    arr = list(map(int, inp().split()))

    # 0이면 종료
    if arr[0] == 0:
        break
    # 0이 아니면
    K = arr[0]
    # combinations 라이브러리를 사용해 집합 S에서 조합 생성
    answers = combinations(arr[1:K+1], 6)

    for answer in answers:
        for num in answer:
            print(num, end=' ')
        print()

    print()

💡TIL

  • itertools.combinations의 반환형은 iterator 객체라서 길이를 구할 때 len()을 쓸 수 없고, 먼저 리스트로 변환해야 한다.
    ex) combination = combinations(arr, 2)
    len(list(combination))

Comment on lines +6 to +15
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

백트래킹 풀이로만 풀었는데 윤상님 풀이로 조합 풀이도 확인할 수 있었습니다! 한주동안 문제 푸느라 수고 많으셨습니다!!

Copy link
Collaborator

@Mingguriguri Mingguriguri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 실력향상에 도움이 되었다니 기쁘네요!! 면접이나 지원서 결과도 좋았으면 좋겠습니당! 저도.. 같이 화이팅하겠습니다!! 저희 스터디원들 모두 좋은 결과가 있기를!

@YoonYn9915 YoonYn9915 merged commit 897f6f7 into main Apr 26, 2025
@github-actions
Copy link

🔥2025-04 챌린지 진행 상황

👉 그래프

  • YoonYn9915: 1개 ❌
  • Mingguriguri: 2개 ❌
  • zaqquum: 4개 ❌

👉 DP

  • YoonYn9915: 2개 ❌
  • Mingguriguri: 6개 ✅
  • zaqquum: 4개 ❌

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