Skip to content
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
44 changes: 39 additions & 5 deletions 윤건수/TestMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,55 @@ public static void main(String[] args) throws Exception {
Programmers programmers = new Programmers();
Leetcode leetcode = new Leetcode();

/*
* 스터디 40주차
* */

// 당구 연습 (Level 2)
// https://school.programmers.co.kr/learn/courses/30/lessons/169198
programmers.setAnswer(new programmers.LV2_169198.Solution()).test();

// 트리 순회 (Gold 4)
// https://www.acmicpc.net/problem/22856
baekJoon.setAnswer(new baekjoon.G4_22856.Main()).test();

// 가장 큰 증가하는 부분 수열 (Silver 2)
// https://www.acmicpc.net/problem/11055
baekJoon.setAnswer(new baekjoon.S2_11055.Main()).test();


/*
* 스터디 39주차
* */

// 전구 (Gold 2)
// https://www.acmicpc.net/problem/2550
// baekJoon.setAnswer(new baekjoon.G2_2550.Main()).test();

// 야근 지수 (Level 3)
// https://school.programmers.co.kr/learn/courses/30/lessons/12927
// programmers.setAnswer(new programmers.LV3_12927.Solution()).test();

// 가장 긴 증가하는 부분 수열 2 (Gold 2)
// https://www.acmicpc.net/problem/12015
// baekJoon.setAnswer(new baekjoon.G2_12015.Main()).test();


/*
* 스터디 38주차
* */

// 말이 되고픈 원숭이 (Gold 3)
// https://www.acmicpc.net/problem/1600
baekJoon.setAnswer(new baekjoon.G3_1600.Main()).test();
// baekJoon.setAnswer(new baekjoon.G3_1600.Main()).test();

// 앱 (Gold 3)
// https://www.acmicpc.net/problem/7579
baekJoon.setAnswer(new baekjoon.G3_7579.Main()).test();
// baekJoon.setAnswer(new baekjoon.G3_7579.Main()).test();

// 배달 (Level 2)
// https://school.programmers.co.kr/learn/courses/30/lessons/12978
programmers.setAnswer(new programmers.LV2_12987.Solution()).test();
// programmers.setAnswer(new programmers.LV2_12987.Solution()).test();


/*
Expand Down Expand Up @@ -125,8 +159,8 @@ public static void main(String[] args) throws Exception {
// 멀티탭 스케쥴링 (Gold 1)
// https://www.acmicpc.net/problem/1700
// baekJoon.setAnswer(new baekjoon.G1_1700.Main()).test();


/*
* 스터디 31주차
* */
Expand Down
90 changes: 90 additions & 0 deletions 윤건수/baekjoon/G4_22856/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package baekjoon.G4_22856;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class Main {

public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int nodeCnt = Integer.parseInt(br.readLine());
Node[] nodes = new Node[nodeCnt + 1];
for (int i = 1; i < nodeCnt + 1; i++) {
nodes[i] = new Node();
nodes[i].num = i;
}


Node emptyNode = new Node();
emptyNode.isVisited = true;
String line = "";
while ((line = br.readLine()) != null) {
int[] info = Arrays.stream(line.split(" ")).mapToInt(Integer::parseInt).toArray();
int nodeNum = info[0];
int leftNodeNum = info[1];
int rightNodeNum = info[2];
Node parentNode = nodes[nodeNum];

if(leftNodeNum != -1){
Node leftNode = nodes[leftNodeNum];
parentNode.left = leftNode;
leftNode.parent = parentNode;
}else{
parentNode.left = emptyNode;
}

if(rightNodeNum != -1){
Node rightNode = nodes[rightNodeNum];
parentNode.right = rightNode;
rightNode.parent = parentNode;
}else {
parentNode.right = emptyNode;
}
}

int root = 1;
int moveCnt = 0;
Node currentNode = nodes[root];
if(currentNode.left.isVisited && currentNode.right.isVisited){
System.out.println(0);
return;
}

Set<Integer> visitedNum = new HashSet<>();
while (true) {
if (currentNode.left.isVisited) {
currentNode.isVisited = true;
visitedNum.add(currentNode.num);

if(visitedNum.size() == nodeCnt) break;
}

if(!currentNode.left.isVisited){
currentNode = currentNode.left;
}else if(!currentNode.right.isVisited){
currentNode = currentNode.right;
}else {
if(currentNode.parent != null) {
currentNode = currentNode.parent;
}

}
moveCnt++;
}

System.out.println(moveCnt);
}

private static class Node{
int num;
Node parent;
Node left;
Node right;
boolean isVisited = false;
}

}
8 changes: 8 additions & 0 deletions 윤건수/baekjoon/G4_22856/input1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
7
1 2 3
2 4 5
3 6 7
4 -1 -1
5 -1 -1
6 -1 -1
7 -1 -1
2 changes: 2 additions & 0 deletions 윤건수/baekjoon/G4_22856/input2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1
1 -1 -1
10 changes: 10 additions & 0 deletions 윤건수/baekjoon/G4_22856/input3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
9
1 2 4
2 3 -1
3 -1 -1
4 5 6
5 -1 -1
6 -1 7
7 8 -1
8 -1 9
9 -1 -1
1 change: 1 addition & 0 deletions 윤건수/baekjoon/G4_22856/result1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10
1 change: 1 addition & 0 deletions 윤건수/baekjoon/G4_22856/result2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
1 change: 1 addition & 0 deletions 윤건수/baekjoon/G4_22856/result3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
13
35 changes: 35 additions & 0 deletions 윤건수/baekjoon/S2_11055/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package baekjoon.S2_11055;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

public static void main(String[] args) throws IOException {

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int cnt = Integer.parseInt(br.readLine());
int[] arr = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
int[] dp = new int[cnt];

for(int i = 0; i < cnt; i++){
int num1 = arr[i];
int beforeSeqIdx = -1;
int result = num1;
for(int j = i - 1; j >= 0; j--){
int num2 = arr[j];
if(num2 < num1) {
result = Math.max(result, dp[j] + num1);
}
}

dp[i] = result;
}

System.out.println(Arrays.stream(dp).max().getAsInt());

}

}
2 changes: 2 additions & 0 deletions 윤건수/baekjoon/S2_11055/input1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
10
1 100 2 50 60 3 5 6 7 8
2 changes: 2 additions & 0 deletions 윤건수/baekjoon/S2_11055/input2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
5
3 2 2 4 5
1 change: 1 addition & 0 deletions 윤건수/baekjoon/S2_11055/result1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
113
1 change: 1 addition & 0 deletions 윤건수/baekjoon/S2_11055/result2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
12
75 changes: 75 additions & 0 deletions 윤건수/programmers/LV2_169198/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package programmers.LV2_169198;

public class Solution {
public int[] solution(int m, int n, int startX, int startY, int[][] balls) {
Point start = new Point(startX, startY);
int[] answer = new int[balls.length];
for(int i = 0; i < balls.length; i++){
Point ball = new Point(balls[i][0], balls[i][1]);
int minDist = Integer.MAX_VALUE;

for(int j = 4; j < 8; j++){
Point point = convertPoint(ball, j, m, n);
if(isValid(j, start, point, ball, m, n)){
int dist = start.calcDist(point);
minDist = Math.min(dist, minDist);
};
}

answer[i] = minDist;
}

return answer;
}

private boolean isValid(int direction, Point point1, Point point2, Point ball, int m, int n){
boolean isBetweenX = ball.y == point1.y
&& (ball.x < Math.max(point1.x, point2.x))
&& (ball.x > Math.min(point1.x, point2.x));
boolean isBetweenY = ball.x == point1.x
&& (ball.y < Math.max(point1.y, point2.y))
&& (ball.y > Math.min(point1.y, point2.y));
return !isBetweenX && !isBetweenY;

}

private Point convertPoint(Point point, int line, int m, int n){
int x = 0;
int y = 0;

switch(line){
case 4: // 좌
x = 0 - point.x;
y = point.y;
break;
case 5: // 위
x = point.x;
y = n + (n - point.y);
break;
case 6: // 우
x = m + (m - point.x);
y = point.y;
break;
case 7: // 하
x = point.x;
y = 0 - point.y;
break;
}

return new Point(x, y);
}

public static class Point{
int x;
int y;

Point(int x, int y){
this.x = x;
this.y = y;
}

public int calcDist(Point o){
return (int)Math.pow((this.x - o.x), 2) + (int)Math.pow((this.y - o.y), 2);
}
}
}
19 changes: 19 additions & 0 deletions 윤건수/programmers/LV2_169198/TestCase.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package programmers.LV2_169198;

import java.util.HashMap;

public class TestCase {

public HashMap<String, Object[]> getInput() {
HashMap<String, Object[]> testCase = new HashMap<>();
testCase.put("case1", new Object[]{10, 10, 3, 7, new int[][]{{7, 7}, {2, 7}, {7, 3}}});
return testCase;
}

public HashMap<String, Object> getResult() {
HashMap<String, Object> resultCase = new HashMap<>();
resultCase.put("case1", new int[]{52, 37, 116});
return resultCase;
}

}