-
Notifications
You must be signed in to change notification settings - Fork 5
240705 김우정 0x0B_0x0C 풀이 #41
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 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,43 @@ | ||
| import java.io.BufferedReader; | ||
| import java.io.IOException; | ||
| import java.io.InputStreamReader; | ||
|
|
||
| public class BOJ_9663 { | ||
| static boolean[] isUsed1 = new boolean[40]; | ||
| static boolean[] isUsed2 = new boolean[40]; | ||
| static boolean[] isUsed3 = new boolean[40]; | ||
|
|
||
| static int count = 0; | ||
| static int n; | ||
|
|
||
| public static void main(String[] args) throws IOException { | ||
| BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
| n = Integer.parseInt(br.readLine()); | ||
|
|
||
| backTracking(0); | ||
|
|
||
| System.out.println(count); | ||
| } | ||
|
|
||
| public static void backTracking(int cur) | ||
| { | ||
| if(cur==n){ | ||
| count++; | ||
| return; | ||
| } | ||
|
|
||
| for(int i=0; i<n; i++){ | ||
| if(isUsed1[i]||isUsed2[i+cur]||isUsed3[cur-i+n-1]) | ||
| continue; | ||
|
|
||
| isUsed1[i] = true; | ||
| isUsed2[i+cur] = true; | ||
| isUsed3[cur-i+n-1] = true; | ||
|
|
||
| backTracking(cur+1); | ||
| isUsed1[i] = false; | ||
| isUsed2[i+cur] = false; | ||
| isUsed3[cur-i+n-1] = false; | ||
| } | ||
| } | ||
| } | ||
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,45 @@ | ||
| import java.io.BufferedReader; | ||
| import java.io.IOException; | ||
| import java.io.InputStreamReader; | ||
| import java.util.StringTokenizer; | ||
|
|
||
| public class BOJ_15650 { | ||
| static int n; | ||
| static int m; | ||
| static int[] arr; | ||
| static boolean[] isUsed; | ||
|
|
||
| public static void main(String[] args) throws IOException { | ||
| BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
| StringTokenizer st = new StringTokenizer(br.readLine()); | ||
|
|
||
| n = Integer.parseInt(st.nextToken()); | ||
| m = Integer.parseInt(st.nextToken()); | ||
|
|
||
| arr = new int[m]; | ||
| isUsed = new boolean[n+1]; | ||
|
|
||
| backTracking(0); | ||
| } | ||
|
|
||
| public static void backTracking(int k){ | ||
| if(k == m){ | ||
| for(int i=0; i<m; i++){ | ||
| System.out.print(arr[i]+" "); | ||
| } | ||
| System.out.println(); | ||
| return; | ||
| } | ||
|
|
||
| for(int i=(k>0?arr[k-1]+1:1); i<=n; i++) | ||
| { | ||
| if(isUsed[i]) continue; | ||
|
|
||
| arr[k]=i; | ||
| isUsed[i]=true; | ||
|
Collaborator
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. 저는 |
||
|
|
||
| backTracking(k+1); | ||
| isUsed[i] = false; | ||
| } | ||
| } | ||
| } | ||
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,37 @@ | ||
| import java.io.BufferedReader; | ||
| import java.io.IOException; | ||
| import java.io.InputStreamReader; | ||
| import java.util.StringTokenizer; | ||
|
|
||
| public class BOJ_1074 { | ||
| public static void main(String[] args) throws IOException { | ||
| BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
| StringTokenizer st = new StringTokenizer(br.readLine()); | ||
|
|
||
| int n = Integer.parseInt(st.nextToken()); | ||
| int r = Integer.parseInt(st.nextToken()); | ||
| int c = Integer.parseInt(st.nextToken()); | ||
|
|
||
| int result = z(r, c, n); | ||
|
|
||
| System.out.println(result); | ||
|
|
||
| br.close(); | ||
| } | ||
|
|
||
| public static int z(int r, int c, int n){ | ||
| if(n==0) | ||
| return 0; | ||
|
|
||
| int half = 1<<n-1; | ||
|
|
||
| if(r<half && c<half) | ||
| return z(r, c, n-1); | ||
| else if(r<half && c>=half) | ||
| return half*half + z(r, c-half, n-1); | ||
| else if(r>=half && c<half) | ||
| return 2*half*half +z(r-half, c, n-1); | ||
| else | ||
| return 3*half*half +z(r-half, c-half, n-1); | ||
| } | ||
| } |
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,60 @@ | ||
| import java.io.BufferedReader; | ||
| import java.io.IOException; | ||
| import java.io.InputStreamReader; | ||
|
|
||
| public class BOJ_2447 { | ||
| static char[][] result; | ||
|
|
||
| public static void main(String[] args) throws IOException { | ||
| BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
| int input = Integer.parseInt(br.readLine()); | ||
|
|
||
| result = new char[input][input]; | ||
|
|
||
| backTracking(0,0, input, false); | ||
|
|
||
| printResult(input); | ||
| } | ||
|
|
||
| public static void backTracking(int x, int y, int n, boolean blank){ | ||
| if(blank){ | ||
| for(int i=x; i<x+n; i++){ | ||
| for(int j=y; j<y+n; j++){ | ||
| result[i][j]=' '; | ||
| } | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| if(n==1) { | ||
| result[x][y] = '*'; | ||
| return; | ||
| } | ||
|
|
||
| int area=0; | ||
| for(int i=x; i<x+n; i+=n/3){ | ||
| for(int j=y; j<y+n; j+=n/3){ | ||
| area++; | ||
| if(area==5){ | ||
| backTracking(i,j,n/3,true); | ||
| } | ||
| else { | ||
| backTracking(i, j, n / 3, false); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public static void printResult(int n){ | ||
| StringBuilder sb = new StringBuilder(); | ||
|
|
||
| for(int i=0; i<n; i++){ | ||
| for(int j=0; j<n; j++){ | ||
| sb.append(result[i][j]); | ||
| } | ||
| sb.append("\n"); | ||
| } | ||
|
|
||
| System.out.print(sb.toString()); | ||
| } | ||
| } |
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,32 @@ | ||
| import java.io.BufferedReader; | ||
| import java.io.IOException; | ||
| import java.io.InputStreamReader; | ||
|
|
||
| public class BOJ_17478 { | ||
| public static void main(String[] args) throws IOException { | ||
| BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
|
|
||
| int n = Integer.parseInt(br.readLine()); | ||
| System.out.println("어느 한 컴퓨터공학과 학생이 유명한 교수님을 찾아가 물었다."); | ||
|
|
||
| recursive(n, ""); | ||
|
|
||
| br.close(); | ||
| } | ||
|
|
||
| public static void recursive(int n, String str){ | ||
| System.out.println(str+"\"재귀함수가 뭔가요?\""); | ||
| if(n==0) { | ||
| System.out.println(str+"\"재귀함수는 자기 자신을 호출하는 함수라네\""); | ||
| } | ||
| else { | ||
| System.out.println(str + "\"잘 들어보게. 옛날옛날 한 산 꼭대기에 이세상 모든 지식을 통달한 선인이 있었어."); | ||
| System.out.println(str + "마을 사람들은 모두 그 선인에게 수많은 질문을 했고, 모두 지혜롭게 대답해 주었지."); | ||
| System.out.println(str + "그의 답은 대부분 옳았다고 하네. 그런데 어느 날, 그 선인에게 한 선비가 찾아와서 물었어.\""); | ||
|
|
||
| recursive(n - 1, str + "____"); | ||
| } | ||
|
|
||
| System.out.println(str+"라고 답변하였지."); | ||
| } | ||
| } |
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.
열, 오른쪽 대각선, 왼쪽 대각선에 퀸이 있는지의 여부를 3개의 배열로 표현하셨군요
저는 row 배열 하나 써서 객 행에 퀸의 위치(열)을 저장하며
같은 열에 있는지 (row[x] == row[i])와대각선에 있는지 (Math.abs(row[x] - row[i]) == x - i)를 검사했습니다!이 차이로 우정님 코드는 isUsed 배열을 통해 O(1), 저는
isAdjacent함수로 각 행마다 퀸의 위치를 확인하기 때문에 O(n)이라서 우정님 코드가 더 효율적인 것 같네요!