### 1. 백트래킹(완전탐색) - 평평하게 벽돌세우기 경우의 수 문제
**예시 문제:**
주어진 벽돌의 높이와 너비가 주어졌을 때, 이를 사용하여 세로로 쌓을 수 있는 벽돌 조합의 수를 구하는 프로그램을 작성하세요. 각 벽돌은 너비는 같지만 높이가 다를 수 있습니다.
```python
def count_wall_combinations(heights):
def backtrack(heights, target_height, idx):
if target_height == 0:
return 1
if target_height < 0 or idx >= len(heights):
return 0
count = 0
for i in range(idx, len(heights)):
count += backtrack(heights, target_height - heights[i], i + 1)
return count
return backtrack(heights, sum(heights), 0)
heights = [1, 2, 3]
print(count_wall_combinations(heights)) # Output: 4
```
### 2. 단순구현 - 누진세 계산 문제
**예시 문제:**
소득이 주어졌을 때, 누진세를 계산하는 프로그램을 작성하세요. 누진세는 다음과 같이 정의됩니다:
- 소득이 10만원 미만이면 세율은 5%입니다.
- 소득이 10만원 이상 20만원 미만이면 세율은 10%입니다.
- 소득이 20만원 이상이면 세율은 20%입니다.
```python
def calculate_tax(income):
if income < 100000:
return income * 0.05
elif income < 200000:
return 100000 * 0.05 + (income - 100000) * 0.1
else:
return 100000 * 0.05 + 100000 * 0.1 + (income - 200000) * 0.2
income = 150000
print(calculate_tax(income)) # Output: 15000.0
```
### 3. 큐, 단순구현 - 은행 손님받기 문제
**예시 문제:**
은행에서 손님이 도착한 순서대로 대기열에 줄을 서고, 순서대로 손님을 받으려고 합니다. 손님의 도착 시간과 업무 소요 시간이 주어졌을 때, 모든 손님이 은행 업무를 마치는 데 걸리는 총 시간을 구하는 프로그램을 작성하세요.
```python
from collections import deque
def total_waiting_time(arrivals, durations):
total_time = 0
current_time = 0
queue = deque()
for arrival, duration in zip(arrivals, durations):
if arrival > current_time:
current_time = arrival
else:
total_time += current_time - arrival
current_time += duration
total_time += duration
return total_time
arrivals = [0, 1, 2, 3]
durations = [5, 3, 2, 1]
print(total_waiting_time(arrivals, durations)) # Output: 17
```
### 4. 테이블2개 SQL - 나누기, 반올림, 조인이 필요한 필요한 문제
**예시 문제:**
학생들의 성적을 관리하는 데이터베이스가 있습니다. 두 개의 테이블 `students`와 `grades`가 있습니다. `students` 테이블은 학생들의 정보를, `grades` 테이블은 학생들의 과목별 성적을 가지고 있습니다. 각 학생의 평균 성적을 반올림하여 구하는 SQL 쿼리를 작성하세요.
```sql
SELECT students.student_id,
ROUND(AVG(grades.grade), 2) AS average_grade
FROM students
JOIN grades ON students.student_id = grades.student_id
GROUP BY students.student_id;
```
이렇게 되겠네요. 원하시는 게 있다면 더 추가해 주세요!
'취준이랄까.. > 코테' 카테고리의 다른 글
백준 5397: 키로거 (0) | 2025.03.26 |
---|---|
런던 비, 건물 사이에 담기는 빗물 총량 (0) | 2024.10.31 |
우선순위 큐 (1) | 2024.05.09 |
list slicing 코드 (0) | 2024.05.09 |
[DFS] 게임 맵 최단거리: 프로그래머스 (0) | 2024.04.20 |