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
34 changes: 0 additions & 34 deletions baekjoon/src/Main.java

This file was deleted.

6 changes: 6 additions & 0 deletions study/week4/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path=""/>
<classpathentry kind="output" path=""/>
</classpath>
17 changes: 17 additions & 0 deletions study/week4/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>week4</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
14 changes: 7 additions & 7 deletions baekjoon/src/com/JUN13164.java → study/week4/JUN13164.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com;
package week;

import java.io.BufferedReader;
import java.io.IOException;
Expand All @@ -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();
}
Expand Down
17 changes: 9 additions & 8 deletions baekjoon/src/com/JUN9663.java → study/week4/JUN9663.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package com;
package week;

import java.util.*;
import java.util.Scanner;
import java.io.FileInputStream;
Expand All @@ -7,26 +8,26 @@ 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개가 놓아지면
{
count++;
return;
}

for(int i = 0; i < queen.length; i++)
{
queen[hight] = i;
Expand All @@ -36,7 +37,7 @@ public static void piece(int hight) // 한 개 씩 놓아보기
}
}
}

public static Boolean check(int x) // 놓을 수 있는지 확인
{
for(int i =0; i < x;i++)
Expand All @@ -52,4 +53,4 @@ else if(Math.abs(x-i) == Math.abs(queen[x]-queen[i])) //대각선에 있는지
}
return true;
}
}
}
8 changes: 0 additions & 8 deletions study/week4/Test.java

This file was deleted.

113 changes: 113 additions & 0 deletions study/week5/JUN10159.java
Original file line number Diff line number Diff line change
@@ -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<Node>{
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<Node>[] 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<Node>();
}

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<Node> 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<Node> 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;
}
}
78 changes: 78 additions & 0 deletions study/week5/JUN1753.java
Original file line number Diff line number Diff line change
@@ -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<Node>{
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<Node>[] 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<Node>();
}

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<Node> 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]));
}
}
}
}
}
Loading