-
Notifications
You must be signed in to change notification settings - Fork 4
[22주차] 이지영 #302
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
[22주차] 이지영 #302
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
19985fb
이지영: [CT] 병원 거리 최소화하기_250210
yeongleej 7fc9cad
이지영: [BOJ] 16724 피리 부는 사나이_250211
yeongleej 917db08
이지영: [PG] 보석 쇼핑_250212
yeongleej 0d44ffa
이지영: [SQL] 식품분류별 가장 비싼 식품의 정보 조회하기_250212
yeongleej 2f6050c
이지영: [BOJ] 18430 무기공학_250213
yeongleej 2a48112
이지영: [BOJ] 1707번 이분 그래프_250214
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
73 changes: 73 additions & 0 deletions
BOJ/1000-5000번/JY_1707.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,73 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
public class JY_1707 { | ||
|
||
static int T, N, M; | ||
static List<Integer>[] g; | ||
static boolean[] visited; | ||
static int[] crr; | ||
static boolean isOk; | ||
|
||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
|
||
T = Integer.parseInt(st.nextToken()); | ||
StringBuilder sb = new StringBuilder(); | ||
for(int t=0; t<T; t++) { | ||
st = new StringTokenizer(br.readLine()); | ||
N = Integer.parseInt(st.nextToken()); | ||
M = Integer.parseInt(st.nextToken()); | ||
|
||
g = new ArrayList[N+1]; | ||
for(int i=1; i<N+1; i++) { | ||
g[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()); | ||
g[a].add(b); | ||
g[b].add(a); | ||
} | ||
|
||
visited = new boolean[N+1]; | ||
crr = new int[N+1]; // 집합 번호 저장 배열 | ||
isOk = true; | ||
for(int i=1; i<N+1; i++) { | ||
if(visited[i]) continue; | ||
dfs(i, 1); | ||
if(!isOk) break; | ||
|
||
} | ||
|
||
if(isOk) sb.append("YES\n"); | ||
else sb.append("NO\n"); | ||
|
||
} | ||
|
||
System.out.println(sb.toString()); | ||
|
||
} | ||
public static void dfs(int now, int group) { | ||
crr[now] = group; | ||
visited[now] = true; | ||
|
||
for(int next: g[now]) { | ||
// 인접 노드가 현재 노드의 그룹과 같다면 fail | ||
if(crr[next] == group) { | ||
isOk = false; | ||
return; | ||
} | ||
|
||
// 방문 X | ||
if(!visited[next]) { | ||
dfs(next, -group); | ||
} | ||
|
||
} | ||
} | ||
|
||
|
||
} |
75 changes: 75 additions & 0 deletions
BOJ/15001-20000번/JY_16724.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,75 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
public class JY_16724 { | ||
|
||
static int N, M; | ||
static char[][] g; | ||
static int[] parent; | ||
// 상 하 좌 우 | ||
static int[] dx = {-1, 1, 0, 0}; | ||
static int[] dy = {0, 0, -1, 1}; | ||
static Map<Character, Integer> cMap; | ||
|
||
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()); | ||
g = new char[N][M]; | ||
|
||
parent = new int[N*M]; | ||
for(int i=0; i<N; i++) { | ||
String line = br.readLine(); | ||
for(int j=0; j<M; j++) { | ||
g[i][j] = line.charAt(j); | ||
parent[i*M+j] = i*M+j; | ||
} | ||
} | ||
|
||
cMap = new HashMap<>(); | ||
cMap.put('U', 0); | ||
cMap.put('D', 1); | ||
cMap.put('L', 2); | ||
cMap.put('R', 3); | ||
|
||
for(int i=0; i<N; i++) { | ||
for(int j=0; j<M; j++) { | ||
int dir = cMap.get(g[i][j]); | ||
int nx = i + dx[dir]; | ||
int ny = j + dy[dir]; | ||
if(find(i*M+j) != find(nx*M+ny)) { | ||
union(i*M+j, nx*M+ny); | ||
} | ||
} | ||
} | ||
|
||
Set<Integer> cSet = new HashSet<>(); | ||
for(int i=0; i<N*M; i++) { | ||
// a <- b <- c 관계에서 모두 parent 값은 a인데 | ||
// a의 parent 값이 변경되면 b, c는 변경되지 않으므로 경로압축을 통한 최종 부모를 찾아줘야 함 | ||
// ** 최종 부모를 찾아주기 위해서 find()후 삽입 | ||
cSet.add(find(parent[i])); | ||
} | ||
System.out.println(cSet.size()); | ||
|
||
|
||
} | ||
public static int find(int x) { | ||
if(x != parent[x]) { | ||
parent[x] = find(parent[x]); | ||
} | ||
return parent[x]; | ||
} | ||
public static void union(int a, int b) { | ||
int pa = find(a); | ||
int pb = find(b); | ||
|
||
if(pa < pb) { | ||
parent[pb] = pa; | ||
} else { | ||
parent[pa] = pb; | ||
} | ||
} | ||
|
||
} |
72 changes: 72 additions & 0 deletions
BOJ/15001-20000번/JY_18430.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,72 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
|
||
public class JY_18430 { | ||
|
||
static int N, M; | ||
static int[][] g; | ||
// 상 좌 하 우 | ||
static int[] dx = {-1, 0, 1, 0}; | ||
static int[] dy = {0, -1, 0, 1}; | ||
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()); | ||
M = Integer.parseInt(st.nextToken()); | ||
|
||
g = new int[N][M]; | ||
for(int i=0; i<N; i++) { | ||
st = new StringTokenizer(br.readLine()); | ||
for(int j=0; j<M; j++) { | ||
g[i][j] = Integer.parseInt(st.nextToken()); | ||
} | ||
} | ||
|
||
visited = new boolean[N][M]; | ||
ans = 0; | ||
dfs(0, 0, 0); | ||
|
||
System.out.println(ans); | ||
} | ||
public static boolean inRange(int x, int y) { | ||
return x>=0 && x<N && y>=0 && y<M; | ||
} | ||
public static void dfs(int x, int y, int score) { | ||
// 다음 행 진행 | ||
if(y == M) { | ||
x += 1; | ||
y = 0; | ||
} | ||
if(x == N) { | ||
ans = Math.max(ans, score); | ||
return; | ||
} | ||
// (x, y) 방문 O | ||
if(!visited[x][y]) { | ||
// 부메랑 반복 | ||
for(int d=0; d<4; d++) { | ||
int ax = x + dx[d]; | ||
int ay = y + dy[d]; | ||
int bx = x + dx[(d+1)%4]; | ||
int by = y + dy[(d+1)%4]; | ||
if(!inRange(ax, ay) || !inRange(bx, by)) continue; | ||
if(visited[ax][ay] || visited[bx][by]) continue; | ||
visited[x][y] = true; | ||
visited[ax][ay] = true; | ||
visited[bx][by] = true; | ||
dfs(x,y+1, score + (g[x][y]*2 +g[ax][ay] + g[bx][by])); | ||
visited[x][y] = false; | ||
visited[ax][ay] = false; | ||
visited[bx][by] = false; | ||
} | ||
} | ||
// (x, y) 방문 X | ||
dfs(x, y+1, score); | ||
|
||
} | ||
|
||
} |
90 changes: 90 additions & 0 deletions
CodeTree/2017-2018년/JY_병원_거리_최소화하기.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,90 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
public class JY_병원_거리_최소화하기 { | ||
|
||
static int N, M; | ||
static int[][] g; | ||
static Map<Integer, Hospital> hMap; | ||
static List<Integer> tList; | ||
static int ans; | ||
static class Hospital { | ||
int num, x, y; | ||
|
||
public Hospital(int num, int x, int y) { | ||
super(); | ||
this.num = num; | ||
this.x = x; | ||
this.y = y; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Hospital [num=" + num + ", x=" + x + ", y=" + y + "]"; | ||
} | ||
|
||
} | ||
|
||
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()); | ||
|
||
g = new int[N][N]; | ||
hMap = new HashMap<>(); | ||
int n = 0; | ||
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()); | ||
if(g[i][j] == 2) { | ||
hMap.put(n, new Hospital(n, i, j)); | ||
n++; | ||
} | ||
} | ||
} | ||
|
||
tList = new ArrayList<>(); | ||
ans = Integer.MAX_VALUE; | ||
// 최대 경우의 수 : 100(사람수) * 13C7 * 7 | ||
comb(0, 0); | ||
|
||
System.out.println(ans); | ||
} | ||
public static void comb(int depth, int start) { | ||
if(depth == M) { | ||
int score = find(tList); | ||
ans = Math.min(ans, score); | ||
return; | ||
} | ||
for(int i=start; i<hMap.size(); i++) { | ||
tList.add(i); | ||
comb(depth+1, i+1); | ||
tList.remove(tList.size()-1); | ||
} | ||
} | ||
public static int cal(int x1, int y1, int x2, int y2) { | ||
return Math.abs(x1-x2) + Math.abs(y1-y2); | ||
} | ||
public static int find(List<Integer> hList) { | ||
int total = 0; | ||
// 사람 반복 | ||
for(int i=0; i<N; i++) { | ||
for(int j=0; j<N; j++) { | ||
if(g[i][j] != 1) continue; | ||
int tmp = Integer.MAX_VALUE; | ||
// 병원 반복 | ||
for(int h : hList) { | ||
Hospital now = hMap.get(h); | ||
int dist = cal(i, j, now.x, now.y); | ||
tmp = Math.min(tmp, dist); | ||
} | ||
total += tmp; | ||
} | ||
} | ||
|
||
return total; | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
Programmers/Level3/JY_67258.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,46 @@ | ||
import java.util.*; | ||
class JY_67258 { | ||
public int[] solution(String[] gems) { | ||
int[] answer = new int[2]; | ||
|
||
// 총 보석 종류구하기 | ||
Set<String> gSet = new HashSet<>(); | ||
for(String g: gems) { | ||
gSet.add(g); | ||
} | ||
int total = gSet.size(); | ||
|
||
|
||
int minR = Integer.MAX_VALUE; | ||
// 투포인터 활용 | ||
int s = 0; | ||
int e = s; | ||
Map<String, Integer> gMap = new HashMap<>(); | ||
while(e < gems.length) { | ||
// System.out.println(">> now: "+gMap+", s:"+s+",e:"+e); | ||
// 보석 추가 | ||
gMap.put(gems[e], gMap.getOrDefault(gems[e], 0)+1); | ||
|
||
// 현재 구간(gMap의 보석들)이 모든 보석을 포함함 | ||
// 총 보석의 개수가 total보다 작을 떄까지 s증가 | ||
while(gMap.keySet().size() == total) { | ||
// 더 짧은 구간 | ||
if(minR > (e-s)) { | ||
minR = (e-s); | ||
answer[0] = s+1; | ||
answer[1] = e+1; | ||
} | ||
// s지점의 보석 감소 | ||
gMap.put(gems[s], gMap.get(gems[s])-1); | ||
// 감소 후, gems[s]의 개수가 0이된다면 gMap에서 삭제 | ||
if(gMap.get(gems[s]) == 0) gMap.remove(gems[s]); | ||
s++; | ||
} | ||
|
||
e++; | ||
|
||
} | ||
|
||
return answer; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
SQL/22주차/JY_식품분류별_가장_비싼_식품의_정보_조회하기.sql
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,11 @@ | ||
-- 식품분류별 가장 비싼 식품의 정보 조회하기 | ||
-- https://school.programmers.co.kr/learn/courses/30/lessons/131116 | ||
SELECT CATEGORY, PRICE AS MAX_PRICE, PRODUCT_NAME | ||
FROM FOOD_PRODUCT | ||
WHERE (CATEGORY, PRICE) IN ( | ||
SELECT CATEGORY, MAX(PRICE) | ||
FROM FOOD_PRODUCT | ||
WHERE CATEGORY IN('과자', '국', '김치', '식용유') | ||
GROUP BY CATEGORY | ||
) | ||
ORDER BY MAX_PRICE DESC |
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.