diff --git a/baekjoon/src/Main.java b/baekjoon/src/Main.java
deleted file mode 100644
index 257c065..0000000
--- a/baekjoon/src/Main.java
+++ /dev/null
@@ -1,34 +0,0 @@
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.util.Arrays;
-import java.util.StringTokenizer;
-import java.util.stream.Stream;
-
-public class Main {
-
- public static void main(String[] args) throws NumberFormatException, IOException {
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- StringTokenizer st = new StringTokenizer(br.readLine());
-
- int N = Integer.parseInt(st.nextToken()); // 학생 수
- int K = Integer.parseInt(st.nextToken()); // 만들 조 수
-
- int[] stature = Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); //학생들 키
- int[] s_sub = new int[N-1];
-
- for(int i = 0; i < N-1; i++) {
- s_sub[i] = stature[i+1] - stature[i]; // 학생들 키의 차이를 저장
- }
-
- Arrays.sort(s_sub); // 차이가 적은 순으로 정력
-
- int ans = 0;
- for(int i = 0; i < N-K; i++) {
- ans+=s_sub[i];
- }
-
- System.out.println(ans);
- br.close();
- }
-}
\ No newline at end of file
diff --git a/study/week4/.classpath b/study/week4/.classpath
new file mode 100644
index 0000000..3f3893a
--- /dev/null
+++ b/study/week4/.classpath
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/study/week4/.project b/study/week4/.project
new file mode 100644
index 0000000..66bab39
--- /dev/null
+++ b/study/week4/.project
@@ -0,0 +1,17 @@
+
+
+ week4
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/baekjoon/src/com/JUN13164.java b/study/week4/JUN13164.java
similarity index 96%
rename from baekjoon/src/com/JUN13164.java
rename to study/week4/JUN13164.java
index 027c750..f53e7d6 100644
--- a/baekjoon/src/com/JUN13164.java
+++ b/study/week4/JUN13164.java
@@ -1,4 +1,4 @@
-package com;
+package week;
import java.io.BufferedReader;
import java.io.IOException;
@@ -12,24 +12,24 @@ public class JUN13164 {
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
-
+
int N = Integer.parseInt(st.nextToken()); // 학생 수
int K = Integer.parseInt(st.nextToken()); // 만들 조 수
-
+
int[] stature = Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); //학생들 키
int[] s_sub = new int[N-1];
-
+
for(int i = 0; i < N-1; i++) {
s_sub[i] = stature[i+1] - stature[i]; // 학생들 키의 차이를 저장
}
-
+
Arrays.sort(s_sub); // 차이가 적은 순으로 정력
-
+
int ans = 0;
for(int i = 0; i < N-K; i++) {
ans+=s_sub[i];
}
-
+
System.out.println(ans);
br.close();
}
diff --git a/baekjoon/src/com/JUN9663.java b/study/week4/JUN9663.java
similarity index 97%
rename from baekjoon/src/com/JUN9663.java
rename to study/week4/JUN9663.java
index 630cb49..26d7a93 100644
--- a/baekjoon/src/com/JUN9663.java
+++ b/study/week4/JUN9663.java
@@ -1,4 +1,5 @@
-package com;
+package week;
+
import java.util.*;
import java.util.Scanner;
import java.io.FileInputStream;
@@ -7,18 +8,18 @@ public class JUN9663 {
static Scanner sc = new Scanner(System.in);
static int count = 0; // n개의 queen을 놓을 수 있는 경우
static int[] queen;
-
+
public static void main(String args[]) throws Exception
{
int n = sc.nextInt(); // 맵 크기 , 놓아야 하는 퀸 갯수
queen = new int[n]; //queen이 놓아지는 y 좌표(열)
-
+
count = 0;
piece(0);
-
+
System.out.println(count);
}
-
+
public static void piece(int hight) // 한 개 씩 놓아보기
{
if(hight == queen.length) // n개가 놓아지면
@@ -26,7 +27,7 @@ public static void piece(int hight) // 한 개 씩 놓아보기
count++;
return;
}
-
+
for(int i = 0; i < queen.length; i++)
{
queen[hight] = i;
@@ -36,7 +37,7 @@ public static void piece(int hight) // 한 개 씩 놓아보기
}
}
}
-
+
public static Boolean check(int x) // 놓을 수 있는지 확인
{
for(int i =0; i < x;i++)
@@ -52,4 +53,4 @@ else if(Math.abs(x-i) == Math.abs(queen[x]-queen[i])) //대각선에 있는지
}
return true;
}
-}
+}
\ No newline at end of file
diff --git a/study/week4/Test.java b/study/week4/Test.java
deleted file mode 100644
index 6e8e486..0000000
--- a/study/week4/Test.java
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-public void Test {
-
- public static void main(String[] args){
- System.out.println("Hello World");
- }
-}
\ No newline at end of file
diff --git a/study/week5/JUN10159.java b/study/week5/JUN10159.java
new file mode 100644
index 0000000..f1deede
--- /dev/null
+++ b/study/week5/JUN10159.java
@@ -0,0 +1,113 @@
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.PriorityQueue;
+import java.util.StringTokenizer;
+
+class Node implements Comparable{
+ int end, re;
+
+ public Node(int next, int re) {
+ this.end = next; // 비교하는 값
+ this.re = re; // 승부 결과 0 : 패, 1 : 승
+ }
+
+ @Override
+ public int compareTo(Node o) {
+ return this.end - o.end; //비교하는 값이 낮은 순으로
+ }
+}
+
+public class JUN10159 {
+
+ static int N, M; // 정점 개수, 간선 개수, 시작 정점
+ static List[] list; // 정점 별 정보 입력할 리스트
+ static int[] result; // 결과를 알 수 있는 수 저장
+ static boolean[] nums; // 1~N 선택 했는지 확인 용
+ public static void main(String[] args) throws IOException {
+ BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
+ StringTokenizer st;
+ StringBuilder an = new StringBuilder();
+
+ N = Integer.parseInt(br.readLine()); // 정점 개수
+ M = Integer.parseInt(br.readLine()); // 간선 개수
+
+ list = new ArrayList[N+1]; // 1 ~ N 로 하기 위해 +1 해서 선언 (-1 하면 귀찮은 거 ㅇㅈ?)
+ result = new int[N+1];
+ nums= new boolean[N+1];
+
+ for(int i = 1; i < list.length; i++) { // 정점 입력 준비
+ list[i] = 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()); // 비교
+ list[a].add(new Node(b, 1)); // 정보 입력 : 비교 대상, 승
+ list[b].add(new Node(a, 0)); // 정보 입력 : 비교 대상, 패
+ }
+
+ for(int i = 1; i < list.length; i++) {
+ if(list[i].isEmpty()) continue;
+ win(i);
+ lose(i);
+ }
+ //System.out.println(Arrays.toString(result));
+ for(int i =1; i < result.length; i++) {
+ an.append((N-1)-result[i]).append("\n");
+ }
+ System.out.print(an);
+ }
+
+ public static void win(int s) {
+ PriorityQueue pq = new PriorityQueue<>();
+ Arrays.fill(nums, false);
+ pq.add(new Node(s, list[s].get(0).re));
+ int cnt = 0;
+ while(!pq.isEmpty()) {
+ Node now = pq.poll(); // 지금 정점의 정보
+ //System.out.println(">>>>>>>>>>>>>> now >>>>>>>>>>>>>>>>");
+ //System.out.println(now.end+" "+now.re);
+ //System.out.println(">>>>>>>>>>>>>>> next >>>>>>>>>>>>>>");
+ for(Node next : list[now.end]) { // 지금 정점과 연결된 정점 가보기
+ //System.out.println(next.end+" "+next.re);
+ if(next.re == 1 && !nums[next.end]) {
+ nums[next.end] = true;
+ cnt++;
+ pq.add(new Node(next.end, 1));
+ }
+ }
+ }
+// System.out.print(s+" ");
+// System.out.println(cnt);
+ result[s] = cnt;
+ }
+ public static void lose(int s) {
+ PriorityQueue pq = new PriorityQueue<>();
+ Arrays.fill(nums, false);
+ pq.add(new Node(s, list[s].get(0).re));
+ int cnt = 0;
+ while(!pq.isEmpty()) {
+ Node now = pq.poll(); // 지금 정점의 정보
+// System.out.println(">>>>>>>>>>>>>> now >>>>>>>>>>>>>>>>");
+// System.out.println(now.end+" "+now.re);
+// System.out.println(">>>>>>>>>>>>>>> next >>>>>>>>>>>>>>");
+ for(Node next : list[now.end]) { // 지금 정점과 연결된 정점 가보기
+ //System.out.println(next.end+" "+next.re);
+ if(next.re == 0 && !nums[next.end]) {
+ nums[next.end] = true;
+ cnt++;
+ pq.add(new Node(next.end, 1));
+ }
+ }
+ }
+// System.out.println(s+" ");
+// System.out.println(cnt);
+ result[s] += cnt;
+ }
+}
\ No newline at end of file
diff --git a/study/week5/JUN1753.java b/study/week5/JUN1753.java
new file mode 100644
index 0000000..3e07631
--- /dev/null
+++ b/study/week5/JUN1753.java
@@ -0,0 +1,78 @@
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.PriorityQueue;
+import java.util.StringTokenizer;
+
+class Node implements Comparable{
+ int end, cost;
+
+ public Node(int next, int cost) {
+ this.end = next; // 다음 목적지
+ this.cost = cost; // 가중치
+ }
+
+ @Override
+ public int compareTo(Node o) {
+ return this.cost - o.cost; //가중치가 낮은 순으로
+ }
+}
+
+public class JUN1753 {
+
+ static int V, E, K; // 정점 개수, 간선 개수, 시작 정점
+ static int INF = 100_000_000;
+ static List[] route; // 정점 별 정보 입력할 리스트
+ static int[] result; // 해당 정점에 가는데 걸린 총 가중치 저장할 배열
+
+ public static void main(String[] args) throws IOException {
+ BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
+ StringTokenizer st =new StringTokenizer(br.readLine());
+
+ V = Integer.parseInt(st.nextToken()); // 정점 개수
+ E = Integer.parseInt(st.nextToken()); // 간선 개수
+ K = Integer.parseInt(br.readLine()); // 시작 정점
+
+ route = new ArrayList[V+1]; // 1 ~ V 로 하기 위해 +1 해서 선언 (-1 하면 귀찮은 거 ㅇㅈ?)
+ result = new int[V+1];
+ Arrays.fill(result, Integer.MAX_VALUE); // 나중에 비교하기 위해 최댓값으로 초기황
+ result[K] = 0;// 자신이(시작지점에서) 자신에게 가는 건 0
+
+ for(int i = 1; i < route.length; i++) { // 정점 입력 준비
+ route[i] = new ArrayList();
+ }
+
+ for(int i = 0; i < E; i++) { //정점 별 정보 입력
+ st = new StringTokenizer(br.readLine());
+ int u = Integer.parseInt(st.nextToken()); // 시작지
+ int v = Integer.parseInt(st.nextToken()); // 도착지
+ int w = Integer.parseInt(st.nextToken()); // 가중치
+ route[u].add(new Node(v, w)); // 정보 입력
+ }
+
+ sum(K);
+
+ for(int i = 1; i < result.length; i++) { // 결과 출력
+ System.out.println((result[i]==Integer.MAX_VALUE)?"INF":result[i]);
+ }
+ }
+
+ public static void sum(int k) {
+ PriorityQueue pq = new PriorityQueue<>();
+ pq.add(new Node(k, 0)); // 시작점은 0
+
+ while(!pq.isEmpty()) {
+ Node now = pq.poll(); // 지금 정점의 정보
+ for(Node next : route[now.end]) { // 지금 정점과 연결된 정점 가보기
+ if(result[next.end] > now.cost + next.cost) { // 기존 결과 값보다 현재 결과 값이 낮으면
+ result[next.end] = now.cost + next.cost;
+ pq.add(new Node(next.end, result[next.end]));
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/study/week5/JUN6198.java b/study/week5/JUN6198.java
new file mode 100644
index 0000000..192c6ab
--- /dev/null
+++ b/study/week5/JUN6198.java
@@ -0,0 +1,99 @@
+package com;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.PriorityQueue;
+import java.util.StringTokenizer;
+
+class Bus implements Comparable{
+ int city, cost;
+
+ public Bus(int city, int cost) {
+ this.city = city;
+ this.cost = cost;
+ }
+
+ @Override
+ public int compareTo(Bus o) { // city가 낮은 번호인 순으로
+ return city - o.city;
+ }
+}
+
+public class JUN6198 {
+ static int N,M;
+ static boolean[] isSelected;
+ static List[] route;
+ static int[][] result;
+ public static void main(String[] args) throws IOException {
+ BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
+ StringTokenizer st;
+ StringBuilder sb = new StringBuilder();
+
+ N = Integer.parseInt(br.readLine()); // 도시의 개수
+ M = Integer.parseInt(br.readLine()); // 버스의 개수
+
+ route = new ArrayList[N+1];
+ result = new int[N+1][N+1];
+ for(int i =0; i <= N; i++) {
+ Arrays.fill(result[i], Integer.MAX_VALUE);
+ }
+
+ for (int i = 1; i <= N; i++) {
+ route[i] = 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()); // 도착 도시
+ int c = Integer.parseInt(st.nextToken()); // 버스 비용
+ route[a].add(new Bus(b, c));
+ }
+
+// for(int i = 1; i < route.length; i++) {
+// System.out.println(" ");
+// for(int j = 0; j < route[i].size(); j++) {
+// System.out.print("< "+route[i].get(j).city+ " "+route[i].get(j).cost+" >");
+// }
+// }System.out.println();
+
+ for(int i = 1; i <= N; i++) {
+ sum(i);
+ for(int j = 1; j < result[i].length; j++) {
+ sb.append(result[i][j]).append(" ");
+ }sb.append("\n");
+ }
+ System.out.println(sb);
+ }
+
+ public static void sum(int s) {
+ PriorityQueue pq = new PriorityQueue<>();
+ pq.add(new Bus(s, 0));
+ result[s][s] = 0;
+// System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
+// System.out.println("<< "+pq.peek().city + "," + pq.peek().cost+" >>");
+ while(!pq.isEmpty()) {
+ Bus now = pq.poll();
+ int x = now.city;
+ for (int i = 0; i < route[x].size(); i++) {
+ int next = route[x].get(i).city;
+ int next_cost = route[x].get(i).cost;
+ //System.out.println("<< "+ next + "," + next_cost+" >>");
+ if(result[s][next] > now.cost + next_cost) {
+ result[s][next] = now.cost + next_cost;
+// System.out.println("--------------------------------------");
+// System.out.println(next+" 까지 비용은 : "+result[s][next]);
+ pq.add(new Bus(next, result[s][next]));
+ }
+ }
+ }
+ for(int i = 1; i < result[s].length; i++) {
+ result[s][i] = result[s][i] == Integer.MAX_VALUE?0:result[s][i];
+ }
+ }
+}
diff --git a/study/week6/JUN2616.java b/study/week6/JUN2616.java
new file mode 100644
index 0000000..c4c2f9d
--- /dev/null
+++ b/study/week6/JUN2616.java
@@ -0,0 +1,44 @@
+package com.home;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.StringTokenizer;
+
+public class JUN2616 {
+ /*
+ * 소형 기관차
+ * 원래 대형 기관차가 N 개의 객차를(안에 사람은 people <= 100) 끌고 가는데 고장이남 ( N <= 50_000 )
+ * 3대의 소형 기관차로 나눠서 가기로 함
+ * 소형 기관차는 M개의 객차만 끌고 갈 수 있음 ( M < N/3)
+ * 이 때 가장 많이 데려가는 경우를 찾아서 손님의 수를 반환해야함.
+ *
+ * */
+
+ static int N, M, max;
+ static int[] people;
+ static int[][] sum;
+ public static void main(String[] args) throws NumberFormatException, IOException {
+ BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
+ StringTokenizer st;
+
+ N = Integer.parseInt(br.readLine()); // 객차 수
+ people = new int[N+1];
+
+ st = new StringTokenizer(br.readLine());
+ for (int i = 1; i < people.length; i++) {
+ people[i] = people[i-1] + Integer.parseInt(st.nextToken());
+ }
+
+
+ M = Integer.parseInt(br.readLine());
+ sum = new int[4][N+1];
+
+ for(int i = 1; i < 4; i++) {
+ for (int j = i * M; j < sum[i].length; j++) {
+ sum[i][j] = Math.max(sum[i][j-1], sum[i-1][j-M] + (people[j] - people[j -M]));
+ }
+ }
+ System.out.println(sum[3][N]);
+ }
+}