-
Notifications
You must be signed in to change notification settings - Fork 26
초급반 / 이지우 / 블랙잭 - 2798, N과M_6 - 15655, 제곱수찾기 - 1025 #60
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package 돌게임.dlwldn30; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
|
||
public class Main { | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
|
||
int N = Integer.parseInt(br.readLine()); | ||
|
||
if(N%2==0){ | ||
System.out.println("CY"); | ||
} | ||
else { | ||
System.out.println("SK"); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package 선수과목.dlwldn30; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
|
||
public class Main { | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
|
||
int N = Integer.parseInt(br.readLine()); | ||
int M = Integer.parseInt(br.readLine()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package 합분해.dlwldn30; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
|
||
public class Main { | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
|
||
int N = Integer.parseInt(br.readLine()); | ||
int K = Integer.parseInt(br.readLine()); | ||
|
||
int[][] dp= new int[K+1][N+1]; | ||
|
||
for (int i = 0; i <= N; i++){ | ||
dp[1][i] = 1; | ||
} | ||
|
||
for (int i = 2; i <= K; i++){ | ||
for (int n = 0; n <= N; n++){ | ||
dp[i][n] = (dp[i][n-1] + dp[i-1][n]) % 1000000000; | ||
} | ||
} | ||
System.out.println(dp[K][N]); | ||
} | ||
|
||
} |
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package N과M_6.dlwldn30; | ||
|
||
import java.io.*; | ||
import java.util.*; | ||
|
||
public class Main { | ||
static int N, M; | ||
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. 재귀에서 사용될 변수는 전역으로 선언해 코드를 간결화하셨는데, 이 방식은 성능상 큰 문제는 없지만, 함수 인지로 전달하는 방식이 테스트 용이성엔 더 좋기에 전역 변수 사용을 지양하고 되도록이면 함수 인자로 사용하는 게 좋을 것 같습니다. |
||
static int[] arr; | ||
static List<Integer> output = new ArrayList<>(); | ||
static StringBuilder sb = new StringBuilder(); | ||
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[N]; | ||
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. 정해진 크기만큼만 할당해 메모리 낭비 없는 점 좋습니다. |
||
st = new StringTokenizer(br.readLine()); | ||
for (int i = 0; i < N; i++) { | ||
arr[i] = Integer.parseInt(st.nextToken()); | ||
} | ||
|
||
Arrays.sort(arr); // 사전순 출력을 위해 정렬 | ||
|
||
solve(0, 0); | ||
|
||
System.out.print(sb); | ||
} | ||
|
||
static void solve(int start, int depth) { | ||
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. solve() 함수명보다 generateCombinations() 또는 dfs()가 의미 전달에 명확하기 때문에 네이밍을 변경하는 게 좋아 보입니다. |
||
if (depth == M) { | ||
for (int num : output) { | ||
sb.append(num).append(' '); | ||
} | ||
sb.append('\n'); | ||
return; | ||
} | ||
|
||
for (int i = start; i < N; i++) { | ||
output.add(arr[i]); | ||
solve(i + 1, depth + 1); | ||
output.remove(output.size() - 1); | ||
} | ||
} | ||
} | ||
|
||
|
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. N과M 문제에서는 출력할 때 메모리 낭비를 막기 위해 StringBuilder를 사용하셨는데, 이 코드에서는 사용하지 않은 점이 아쉽습니다. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package 블랙잭.dlwldn30; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.StringTokenizer; | ||
|
||
public class Main { | ||
|
||
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 M = Integer.parseInt(st.nextToken()); | ||
int max = 0; | ||
|
||
int[] cards = new int[N]; | ||
st = new StringTokenizer(br.readLine()); | ||
|
||
for (int i = 0; i < N; i++) { | ||
cards[i] = Integer.parseInt(st.nextToken()); | ||
} | ||
|
||
for (int i = 0; i < N - 2; i++) { | ||
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 (int j = i + 1; j < N - 1; j++) { | ||
for (int k = j + 1; k < N; k++) { | ||
int sum = cards[i] + cards[j] + cards[k]; | ||
if (sum <= M) { | ||
max = Math.max(max, sum); | ||
} | ||
} | ||
} | ||
} | ||
|
||
System.out.println(max); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package 제곱수찾기.dlwldn30; | ||
|
||
public class Main { | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package 선수과목.dlwldn30; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.*; | ||
|
||
public class Main { | ||
|
||
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 m = Integer.parseInt(st.nextToken()); // 선수 조건 수 | ||
|
||
int[] degree = new int[n+1]; // 선수 과목들 수 | ||
int[] semester = new int[n+1]; | ||
|
||
List<List<Integer>> array = new ArrayList<List<Integer>>(); | ||
for (int i = 0; i <=n; i++) { | ||
array.add(new ArrayList<>()); | ||
} | ||
|
||
for (int i = 0; i <m; i++) { | ||
st = new StringTokenizer(br.readLine()); | ||
int a = Integer.parseInt(st.nextToken()); | ||
int b = Integer.parseInt(st.nextToken()); | ||
array.get(a).add(b); | ||
degree[b]++; | ||
} | ||
|
||
Queue<Integer> queue = new LinkedList<>(); | ||
|
||
|
||
//선수 과목 없는 것들 | ||
for (int i = 1; i<= n; i++){ | ||
if (degree[i] == 0){ | ||
queue.add(i); | ||
semester[i] = 1; | ||
} | ||
} | ||
|
||
while (!queue.isEmpty()){ | ||
int cur = queue.poll(); // 선수과목에서 처음부터 차근차근 | ||
for (int i : array.get(cur)){ // 얘랑 연결된 과목 | ||
degree[i]--; | ||
if (semester[i] <= semester[cur]){ | ||
semester[i] = semester[cur]+1; | ||
} | ||
if(degree[i] == 0){ | ||
queue.add(i); | ||
} | ||
} | ||
} | ||
// 결과 출력 | ||
StringBuilder sb = new StringBuilder(); | ||
for (int i = 1; i <= n; i++) { | ||
sb.append(semester[i]).append(" "); | ||
} | ||
|
||
System.out.println(sb.toString()); | ||
|
||
} | ||
|
||
|
||
} |
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.
전반적인 구조는 아주 깔끔하고 잘 구성되어 있습니다!
그러나 문제의 핵심 조건 중 하나인 중복 수열 제거가 누락되어 있기 때문에 이걸 보완해야 완전한 풀이라고 생각합니다.
CS 지식 기반으로 보면 시간/공간 복잡도 측면에서는 좋은 코드 같습니다.