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

Open
wants to merge 2 commits into
base: lsh1215
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions 프로그래머스/1/42840. 모의고사/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# [level 1] 모의고사 - 42840

[문제 링크](https://school.programmers.co.kr/learn/courses/30/lessons/42840)

### 성능 요약

메모리: 88.7 MB, 시간: 0.99 ms

### 구분

코딩테스트 연습 > 완전탐색

### 채점결과

정확성: 100.0<br/>합계: 100.0 / 100.0

### 제출 일자

2024년 12월 17일 11:02:03

### 문제 설명

<p>수포자는 수학을 포기한 사람의 준말입니다. 수포자 삼인방은 모의고사에 수학 문제를 전부 찍으려 합니다. 수포자는 1번 문제부터 마지막 문제까지 다음과 같이 찍습니다.</p>

<p>1번 수포자가 찍는 방식: 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, ...<br>
2번 수포자가 찍는 방식: 2, 1, 2, 3, 2, 4, 2, 5, 2, 1, 2, 3, 2, 4, 2, 5, ...<br>
3번 수포자가 찍는 방식: 3, 3, 1, 1, 2, 2, 4, 4, 5, 5, 3, 3, 1, 1, 2, 2, 4, 4, 5, 5, ...</p>

<p>1번 문제부터 마지막 문제까지의 정답이 순서대로 들은 배열 answers가 주어졌을 때, 가장 많은 문제를 맞힌 사람이 누구인지 배열에 담아 return 하도록 solution 함수를 작성해주세요.</p>

<h5>제한 조건</h5>

<ul>
<li>시험은 최대 10,000 문제로 구성되어있습니다.</li>
<li>문제의 정답은 1, 2, 3, 4, 5중 하나입니다.</li>
<li>가장 높은 점수를 받은 사람이 여럿일 경우, return하는 값을 오름차순 정렬해주세요.</li>
</ul>

<h5>입출력 예</h5>
<table class="table">
<thead><tr>
<th>answers</th>
<th>return</th>
</tr>
</thead>
<tbody><tr>
<td>[1,2,3,4,5]</td>
<td>[1]</td>
</tr>
<tr>
<td>[1,3,2,4,2]</td>
<td>[1,2,3]</td>
</tr>
</tbody>
</table>
<h5>입출력 예 설명</h5>

<p>입출력 예 #1</p>

<ul>
<li>수포자 1은 모든 문제를 맞혔습니다.</li>
<li>수포자 2는 모든 문제를 틀렸습니다.</li>
<li>수포자 3은 모든 문제를 틀렸습니다.</li>
</ul>

<p>따라서 가장 문제를 많이 맞힌 사람은 수포자 1입니다.</p>

<p>입출력 예 #2</p>

<ul>
<li>모든 사람이 2문제씩을 맞췄습니다.</li>
</ul>


> 출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/challenges
28 changes: 28 additions & 0 deletions 프로그래머스/1/42840. 모의고사/모의고사.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import java.util.*;

class Solution {
public List<Integer> solution(int[] answers) {
int[] pattern1 = {1, 2, 3, 4, 5};
int[] pattern2 = {2, 1, 2, 3, 2, 4, 2, 5};
int[] pattern3 = {3, 3, 1, 1, 2, 2, 4, 4, 5, 5};

int[] scores = new int[3];

for (int i = 0; i < answers.length; i++) {
if (answers[i] == pattern1[i % pattern1.length]) scores[0]++;
if (answers[i] == pattern2[i % pattern2.length]) scores[1]++;
if (answers[i] == pattern3[i % pattern3.length]) scores[2]++;
}

int maxScore = Math.max(scores[0], Math.max(scores[1], scores[2]));

List<Integer> result = new ArrayList<>();
for (int i = 0; i < scores.length; i++) {
if (scores[i] == maxScore) {
result.add(i + 1);
}
}

return result;
}
}
111 changes: 111 additions & 0 deletions 프로그래머스/1/86491. 최소직사각형/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# [level 1] 최소직사각형 - 86491

[문제 링크](https://school.programmers.co.kr/learn/courses/30/lessons/86491)

### 성능 요약

메모리: 86.6 MB, 시간: 1.81 ms

### 구분

코딩테스트 연습 > 완전탐색

### 채점결과

정확성: 100.0<br/>합계: 100.0 / 100.0

### 제출 일자

2024년 12월 17일 10:54:04

### 문제 설명

<p>명함 지갑을 만드는 회사에서 지갑의 크기를 정하려고 합니다. 다양한 모양과 크기의 명함들을 모두 수납할 수 있으면서, 작아서 들고 다니기 편한 지갑을 만들어야 합니다. 이러한 요건을 만족하는 지갑을 만들기 위해 디자인팀은 모든 명함의 가로 길이와 세로 길이를 조사했습니다.</p>

<p>아래 표는 4가지 명함의 가로 길이와 세로 길이를 나타냅니다.</p>
<table class="table">
<thead><tr>
<th>명함 번호</th>
<th>가로 길이</th>
<th>세로 길이</th>
</tr>
</thead>
<tbody><tr>
<td>1</td>
<td>60</td>
<td>50</td>
</tr>
<tr>
<td>2</td>
<td>30</td>
<td>70</td>
</tr>
<tr>
<td>3</td>
<td>60</td>
<td>30</td>
</tr>
<tr>
<td>4</td>
<td>80</td>
<td>40</td>
</tr>
</tbody>
</table>
<p>가장 긴 가로 길이와 세로 길이가 각각 80, 70이기 때문에 80(가로) x 70(세로) 크기의 지갑을 만들면 모든 명함들을 수납할 수 있습니다. 하지만 2번 명함을 가로로 눕혀 수납한다면 80(가로) x 50(세로) 크기의 지갑으로 모든 명함들을 수납할 수 있습니다. 이때의 지갑 크기는 4000(=80 x 50)입니다.</p>

<p>모든 명함의 가로 길이와 세로 길이를 나타내는 2차원 배열 sizes가 매개변수로 주어집니다. 모든 명함을 수납할 수 있는 가장 작은 지갑을 만들 때, 지갑의 크기를 return 하도록 solution 함수를 완성해주세요.</p>

<hr>

<h5>제한사항</h5>

<ul>
<li>sizes의 길이는 1 이상 10,000 이하입니다.

<ul>
<li>sizes의 원소는 [w, h] 형식입니다.</li>
<li>w는 명함의 가로 길이를 나타냅니다.</li>
<li>h는 명함의 세로 길이를 나타냅니다.</li>
<li>w와 h는 1 이상 1,000 이하인 자연수입니다.</li>
</ul></li>
</ul>

<hr>

<h5>입출력 예</h5>
<table class="table">
<thead><tr>
<th>sizes</th>
<th>result</th>
</tr>
</thead>
<tbody><tr>
<td>[[60, 50], [30, 70], [60, 30], [80, 40]]</td>
<td>4000</td>
</tr>
<tr>
<td>[[10, 7], [12, 3], [8, 15], [14, 7], [5, 15]]</td>
<td>120</td>
</tr>
<tr>
<td>[[14, 4], [19, 6], [6, 16], [18, 7], [7, 11]]</td>
<td>133</td>
</tr>
</tbody>
</table>
<hr>

<h5>입출력 예 설명</h5>

<p>입출력 예 #1<br>
문제 예시와 같습니다.</p>

<p>입출력 예 #2<br>
명함들을 적절히 회전시켜 겹쳤을 때, 3번째 명함(가로: 8, 세로: 15)이 다른 모든 명함보다 크기가 큽니다. 따라서 지갑의 크기는 3번째 명함의 크기와 같으며, 120(=8 x 15)을 return 합니다.</p>

<p>입출력 예 #3<br>
명함들을 적절히 회전시켜 겹쳤을 때, 모든 명함을 포함하는 가장 작은 지갑의 크기는 133(=19 x 7)입니다.</p>


> 출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/challenges
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Solution {
public int solution(int[][] sizes) {
int maxWidth = 0;
int maxHeight = 0;


for (int[] size : sizes) {
int width = Math.max(size[0], size[1]); // 큰 값을 가로로
int height = Math.min(size[0], size[1]); // 작은 값을 세로로

// 가로, 세로 최댓값 갱신
maxWidth = Math.max(maxWidth, width);
maxHeight = Math.max(maxHeight, height);
}

return maxWidth * maxHeight;
}
}