-
Notifications
You must be signed in to change notification settings - Fork 4
[9주차] 이지영 #119
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
[9주차] 이지영 #119
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
86bf71a
이지영: [PG] 64062 징검다리 건너기_241104
yeongleej 7da6abc
이지영: [CT] 전투 로봇_241104
yeongleej 797fec9
이지영: [BOJ] 2660 회장뽑기_241105
yeongleej 454fef4
이지영: [SQL] 상품을 구매한 회원 비율_241105
yeongleej 345fb02
이지영: [SQL] 상품을 구매한 회원 비율 구하기_231105-1
yeongleej 445bcad
이지영: [BOJ] 2098 외판원 순회_241106
yeongleej 74db40e
이지영: [BOJ] 13164 행복 유치원_241108
yeongleej 6db3a84
이지영: [BOJ] 14620 꽃길_241108
yeongleej 9afbad0
이지영: [SQL] 대장균 크기에 따라 분류하기 2_241108
yeongleej 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
101 changes: 101 additions & 0 deletions
BOJ/1000-5000번/JY_2660.java
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,101 @@ | ||
package day1105; | ||
|
||
import java.io.*; | ||
import java.util.*; | ||
|
||
public class JY_2660 { | ||
|
||
static int INF = Integer.MAX_VALUE; | ||
static int N; | ||
static List<Node>[] g; | ||
static int[] distance; | ||
static class Node implements Comparable<Node> { | ||
int w, dist; | ||
public Node(int w, int dist) { | ||
this.w = w; | ||
this.dist = dist; | ||
} | ||
@Override | ||
public int compareTo(Node other) { | ||
return this.dist - other.dist; | ||
} | ||
} | ||
|
||
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()); | ||
|
||
g = new ArrayList[N+1]; | ||
for(int i=1; i<N+1; i++) { | ||
g[i] = new ArrayList<>(); | ||
} | ||
|
||
while(true) { | ||
st = new StringTokenizer(br.readLine()); | ||
int n1 = Integer.parseInt(st.nextToken()); | ||
int n2 = Integer.parseInt(st.nextToken()); | ||
if(n1 == -1 && n2 == -1) break; | ||
g[n1].add(new Node(n2, 1)); | ||
g[n2].add(new Node(n1, 1)); | ||
} | ||
|
||
int minLevel = Integer.MAX_VALUE; | ||
List<Integer> aList = new ArrayList<>(); | ||
for(int i=1; i<N+1; i++) { | ||
distance = new int[N+1]; | ||
Arrays.fill(distance, INF); | ||
|
||
dijkstra(i); | ||
// System.out.println(i+": "+Arrays.toString(distance)); | ||
|
||
int level = findLevel(); | ||
|
||
if(level < minLevel) { | ||
aList = new ArrayList<>(); | ||
aList.add(i); | ||
minLevel = level; | ||
|
||
} else if (level == minLevel) { | ||
aList.add(i); | ||
} | ||
} | ||
|
||
System.out.println(minLevel+" "+aList.size()); | ||
for(int i: aList) { | ||
System.out.print(i+" "); | ||
} | ||
System.out.println(); | ||
|
||
} | ||
public static void dijkstra(int n) { | ||
PriorityQueue<Node> pq = new PriorityQueue<>(); | ||
pq.add(new Node(n, 0)); | ||
|
||
distance[n] = 0; | ||
|
||
while(!pq.isEmpty()) { | ||
Node now = pq.poll(); | ||
|
||
if(now.dist > distance[now.w]) continue; | ||
|
||
for(Node next: g[now.w]) { | ||
int cost = now.dist + next.dist; | ||
if(cost < distance[next.w]) { | ||
distance[next.w] = cost; | ||
pq.add(new Node(next.w, cost)); | ||
} | ||
} | ||
} | ||
} | ||
public static int findLevel() { | ||
int maxL = Integer.MIN_VALUE; | ||
for(int i=1; i<N+1; i++) { | ||
maxL = Math.max(maxL, distance[i]); | ||
} | ||
|
||
return maxL; | ||
} | ||
|
||
} |
66 changes: 66 additions & 0 deletions
BOJ/1000-5000번/JY_2908.java
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,66 @@ | ||
package day1106; | ||
|
||
import java.io.*; | ||
import java.util.*; | ||
|
||
public class JY_2908 { | ||
|
||
static int INF = 15_000_000; | ||
static int FullBit; | ||
static int N; | ||
static int[][] w; | ||
static int[][] dp; | ||
|
||
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()); | ||
|
||
w = new int[N][N]; | ||
for(int i=0; i<N; i++) { | ||
st = new StringTokenizer(br.readLine()); | ||
for(int j=0; j<N; j++) { | ||
w[i][j] = Integer.parseInt(st.nextToken()); | ||
} | ||
} | ||
|
||
// 모든 노드를 방문한 비트마스킹 값 | ||
FullBit = (1 << N); | ||
|
||
dp = new int[N][FullBit]; | ||
for(int i=0; i<N; i++) { | ||
Arrays.fill(dp[i], -1); | ||
} | ||
|
||
// 0번째 노드부터 시작 | ||
System.out.println(dfs(0, 1)); | ||
} | ||
public static int dfs(int now, int visited) { | ||
// 모든 정점 방문 | ||
if(visited == FullBit-1) { | ||
if(w[now][0] == 0) return INF; | ||
return w[now][0]; | ||
} | ||
|
||
// 이미 방문한 노드 | ||
if(dp[now][visited] != -1) return dp[now][visited]; | ||
|
||
// 아직 방문 X | ||
dp[now][visited] = INF; | ||
|
||
for(int i=0; i<N; i++) { | ||
// i로 가는 것 방문처리 | ||
int next = visited | (1 << i); | ||
|
||
// i로 가는 경로가 없거나, 이미 방문했다면 continue | ||
if(w[now][i] == 0) continue; | ||
if((visited & (1 << i)) != 0) continue; | ||
|
||
dp[now][visited] = Math.min(dp[now][visited], dfs(i, next) + w[now][i]); | ||
} | ||
|
||
return dp[now][visited]; | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
BOJ/10001-15000번/JY_13164.java
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,36 @@ | ||
package day1108; | ||
|
||
import java.io.*; | ||
import java.util.*; | ||
|
||
public class JY_13164 { | ||
|
||
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 K = Integer.parseInt(st.nextToken()); | ||
|
||
List<Integer> dList = new ArrayList<>(); | ||
st = new StringTokenizer(br.readLine()); | ||
int n1 = Integer.parseInt(st.nextToken()); | ||
for(int i=1; i<N; i++) { | ||
int n2 = Integer.parseInt(st.nextToken()); | ||
dList.add(n2 - n1); | ||
n1 = n2; | ||
} | ||
|
||
Collections.sort(dList); | ||
// System.out.println(dList); | ||
|
||
// 뒤의 (K-1)개의 차이를 없애야 함 | ||
int ans = 0; | ||
for(int i=0; i<N-K; i++) { | ||
ans += dList.get(i); | ||
} | ||
|
||
System.out.println(ans); | ||
} | ||
|
||
} |
84 changes: 84 additions & 0 deletions
BOJ/10001-15000번/JY_14620.java
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,84 @@ | ||
package day1108; | ||
|
||
import java.io.*; | ||
import java.util.*; | ||
|
||
public class JY_14620 { | ||
|
||
static int N; | ||
static int[][] g; | ||
static int[] dx = {0, 0, -1, 1}; | ||
static int[] dy = {-1, 1, 0, 0}; | ||
static boolean[][] visited; | ||
static int ans; | ||
|
||
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()); | ||
|
||
g = new int[N][N]; | ||
|
||
for(int i=0; i<N; i++) { | ||
st = new StringTokenizer(br.readLine()); | ||
for(int j=0; j<N; j++) { | ||
g[i][j] = Integer.parseInt(st.nextToken()); | ||
} | ||
} | ||
|
||
ans = Integer.MAX_VALUE; | ||
visited = new boolean[N][N]; | ||
findSpot(0, 0, 0, 0); | ||
|
||
System.out.println(ans); | ||
|
||
} | ||
public static boolean inRange(int x, int y) { | ||
return x>=0 && x<N && y>=0 && y<N; | ||
} | ||
public static boolean isOk(int x, int y) { | ||
if(visited[x][y]) return false; | ||
for(int i=0; i<4; i++) { | ||
int nx = x + dx[i]; | ||
int ny = y + dy[i]; | ||
if(visited[nx][ny]) return false; | ||
} | ||
|
||
return true; | ||
} | ||
public static void findSpot(int x, int y, int depth, int cost) { | ||
if(depth == 3) { | ||
ans = Math.min(ans, cost); | ||
return; | ||
} | ||
|
||
for(int i=1; i<N-1; i++) { | ||
for(int j=1; j<N-1; j++) { | ||
if(x==i && y==j) continue; | ||
if(!isOk(i, j)) continue; | ||
|
||
int c = g[i][j]; | ||
visited[i][j] = true; | ||
for(int d=0; d<4; d++) { | ||
int nx = i + dx[d]; | ||
int ny = j + dy[d]; | ||
visited[nx][ny] = true; | ||
c += g[nx][ny]; | ||
} | ||
|
||
findSpot(i, j, depth+1, cost+c); | ||
|
||
visited[i][j] = false; | ||
for(int d=0; d<4; d++) { | ||
int nx = i + dx[d]; | ||
int ny = j + dy[d]; | ||
visited[nx][ny] = false; | ||
} | ||
|
||
} | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.
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.