-
Notifications
You must be signed in to change notification settings - Fork 0
FEAT: 프로그래머스 카펫 - 완전탐색 #10
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
Open
anso33
wants to merge
2
commits into
main
Choose a base branch
from
0328
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| package bruteForceSearch; | ||
|
|
||
| /* | ||
| * 소수 찾기, level2 : https://school.programmers.co.kr/learn/courses/30/lessons/42839 | ||
| * 1. 조합으로 숫자의 경우의 수를 찾고 | ||
| * 2. for문을 돌면서 나눠지는 숫자가 있는지 확인한다. (없으면 소수) | ||
| * | ||
| * 훔냐ㅑ 답안지 슥삭 했습니다..... | ||
| * 슥삭한 블로그 : https://dding9code.tistory.com/18 | ||
| * 1. 소수를 판단하는 함수 + DFS로 숫자를 조합하는 함수를 구현한다. | ||
| * */ | ||
|
|
||
| import java.util.ArrayList; | ||
|
|
||
| public class pg_42839 { | ||
|
|
||
| // 숫자 조합을 저장할 ArrayList | ||
| static ArrayList<Integer> arr = new ArrayList<>(); | ||
| // 같은 숫자 중복을 확인하기 위한 배열 | ||
| static boolean[] check = new boolean[7]; | ||
|
|
||
| public int solution(String numbers) { | ||
| int answer = 0; | ||
|
|
||
| for (int i = 0; i < numbers.length(); i++) { | ||
| dfs(numbers, "", i + 1); | ||
| } | ||
|
|
||
| for (int i = 0; i < arr.size(); i++) { | ||
| if (prime(arr.get(i))) { | ||
| answer++; | ||
| } | ||
| } | ||
|
|
||
| return answer; | ||
| } | ||
|
|
||
| private void dfs(String numbers, String s, int m) { | ||
| if (s.length() == m) { | ||
| int num = Integer.parseInt(s); | ||
| if (!arr.contains(num)) { // 이미 만들어진 숫자 거르기 | ||
| arr.add(num); | ||
| } | ||
| } | ||
| for (int i = 0; i < numbers.length(); i++) { | ||
| if (!check[i]) { | ||
| check[i] = true; | ||
| s += numbers.charAt(i); | ||
| dfs(numbers, s, m); | ||
| check[i] = false; | ||
| s = s.substring(0, s.length() - 1); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private boolean prime(int n) { | ||
| if (n < 2) { | ||
| return false; | ||
| } | ||
| for (int i = 2; i * i <= n; i++) { | ||
| if (n % i == 0) { | ||
| return false; | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package bruteForceSearch; | ||
|
|
||
| /* | ||
| * 완전탐색 level2 | ||
| * 카펫 :https://school.programmers.co.kr/learn/courses/30/lessons/42842 | ||
| * 노란색의 가로 세로를 x, y | 갈색의 가로 세로를 x+2, y+2 로 두고 넓이를 이용한 방정식을 통해 해결 | ||
| * */ | ||
|
|
||
| public class pg_42842 { | ||
|
|
||
| public int[] solution(int brown, int yellow) { | ||
| int x = 0; | ||
| // y = brownSum - x; | ||
| int brownSum = (brown - 4) / 2; | ||
|
|
||
| for (int i = 0; i < 2500; i++) { | ||
| if (i * (brownSum - i) == yellow) { | ||
| x = i; | ||
| break; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이거 걍
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 지수님 처럼! 맞아여 for문안에서 return 할 생각을 못함ㅋㅋㅋ |
||
| } | ||
| } | ||
| int[] answer = {brownSum + 2 - x, x + 2}; | ||
| return answer; | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
전 0인 경우는 존재하지 않는다고 생각해서( 이유 : yellow 가 1 이상이면 그럴 일이 없습니다) 3부터 돌아줬읍니당
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.
맞아요ㅋㅎㅋㅎ 사실 2500까지도 안갔어도 됐을 것 같습니다ㅎㅎㅎ 반성반성