-
Notifications
You must be signed in to change notification settings - Fork 4
[12주차] 이지영 #168
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
[12주차] 이지영 #168
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2fd3aca
이지영: [CT] 생명과학부 랩 인턴_241125
yeongleej 5525b8b
이지영: [PG] 64064 불량 사용자_241127
yeongleej 95e0db4
이지영: [BOJ] 2352 반도체 설계_241127
yeongleej 3bae557
이지영: [BOJ] 28707 배열 정렬_241126
yeongleej 5ce201b
이지영: [SQL] Investments in 2016_241126
yeongleej 0f59ba8
이지영: [PG] 17686 파일명 정렬_241130
yeongleej e9b3198
이지영: [SQL] 자동차 대여 기록 별 대여 금액 구하기_241130
yeongleej 26821c3
(수정) 이지영: [SQL] 자동차 대여 기록 별 금액 구하기_241130
yeongleej be5d092
이지영: [BOJ] 2533 사회망 서비스(SNS)_241130
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
58 changes: 58 additions & 0 deletions
BOJ/1000-5000번/JY_2352.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,58 @@ | ||
package day1127; | ||
|
||
import java.io.*; | ||
import java.util.*; | ||
|
||
public class JY_2352 { | ||
|
||
static int N; | ||
static List<Integer> lines; | ||
|
||
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()); | ||
|
||
int[] arr = new int[N]; | ||
st = new StringTokenizer(br.readLine()); | ||
for(int i=0; i<N; i++) { | ||
arr[i] = Integer.parseInt(st.nextToken()); | ||
} | ||
|
||
lines = new ArrayList<>(); | ||
lines.add(arr[0]); | ||
|
||
for(int i=1; i<N; i++) { | ||
if(lines.get(lines.size()-1) < arr[i]) { | ||
lines.add(arr[i]); | ||
} else { | ||
// 이분 탐색으로 적절한 위치 찾고 삽입 | ||
int idx = findPos(arr[i]); | ||
lines.set(idx, arr[i]); | ||
} | ||
} | ||
|
||
int ans = lines.size(); | ||
System.out.println(ans); | ||
|
||
} | ||
public static int findPos(int num) { | ||
int s = 0; | ||
int e = lines.size()-1; | ||
int ans = 0; | ||
while(s <= e) { | ||
int mid = (s + e) / 2; | ||
if(lines.get(mid) >= num) { | ||
ans = mid; | ||
e = mid - 1; | ||
} else { | ||
s = mid + 1; | ||
} | ||
} | ||
|
||
return ans; | ||
} | ||
|
||
|
||
} |
57 changes: 57 additions & 0 deletions
BOJ/1000-5000번/JY_2533.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,57 @@ | ||
package day1128; | ||
|
||
import java.io.*; | ||
import java.util.*; | ||
|
||
public class JY_2533 { | ||
|
||
static int N; | ||
static List<Integer>[] g; | ||
static int[][] dp; | ||
static boolean[] visited; | ||
|
||
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<>(); | ||
} | ||
|
||
for(int i=0; i<N-1; 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); | ||
} | ||
|
||
// dp[p][0] : 부모가 얼리어답터 X | ||
// dp[p][1] : 부모가 얼리어답터 O | ||
dp = new int[N+1][2]; | ||
for(int i=0; i<N+1; i++) { | ||
dp[i][1] = 1; | ||
} | ||
|
||
visited = new boolean[N+1]; | ||
visited[1] = true; | ||
dfs(1); | ||
System.out.println(Math.min(dp[1][0], dp[1][1])); | ||
|
||
} | ||
public static void dfs(int now) { | ||
for(int next: g[now]) { | ||
if(visited[next]) continue; | ||
visited[next] = true; | ||
dfs(next); | ||
// now가 얼리어답터가 아니라면 자식들이 모두 얼리어답터 | ||
dp[now][0] += dp[next][1]; | ||
// now가 얼리어답터라면 자식들 중 최소 얼리어답터 구하기 | ||
dp[now][1] += Math.min(dp[next][0], dp[next][1]); | ||
} | ||
} | ||
|
||
} |
118 changes: 118 additions & 0 deletions
BOJ/30000-35000번/JY_28707.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,118 @@ | ||
package day1126; | ||
|
||
import java.io.*; | ||
import java.util.*; | ||
|
||
public class JY_28707 { | ||
|
||
static int N, M; | ||
static int[] orr; | ||
static int[][] crr; | ||
static Map<Integer, Integer> cMap; | ||
static class Node implements Comparable<Node> { | ||
int[] arr; | ||
int num, cost; | ||
|
||
public Node(int[] arr, int num, int cost) { | ||
super(); | ||
this.arr = arr; | ||
this.num = num; | ||
this.cost = cost; | ||
} | ||
|
||
@Override | ||
public int compareTo(Node other) { | ||
return this.cost - other.cost; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Node [arr=" + Arrays.toString(arr) + ", num=" + num + ", cost=" + cost + "]"; | ||
} | ||
|
||
} | ||
|
||
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()); | ||
|
||
orr = new int[N]; | ||
st = new StringTokenizer(br.readLine()); | ||
for(int i=0; i<N; i++) { | ||
orr[i] = Integer.parseInt(st.nextToken()); | ||
} | ||
|
||
M = Integer.parseInt(br.readLine()); | ||
// 명령 리스트 | ||
crr = new int[M][3]; | ||
for(int i=0; i<M; i++) { | ||
st = new StringTokenizer(br.readLine()); | ||
crr[i][0] = Integer.parseInt(st.nextToken()) -1; | ||
crr[i][1] = Integer.parseInt(st.nextToken()) -1; | ||
crr[i][2] = Integer.parseInt(st.nextToken()); | ||
} | ||
|
||
cMap = new HashMap<>(); | ||
|
||
dijkstra(); | ||
// System.out.println(cMap); | ||
|
||
// 비내림차순 노드 찾기 | ||
Arrays.sort(orr); | ||
int num = arrayToInt(orr); | ||
if(cMap.containsKey(num)) { | ||
System.out.println(cMap.get(num)); | ||
} else { | ||
System.out.println(-1); | ||
} | ||
|
||
} | ||
public static int arrayToInt(int[] brr) { | ||
int val = 1; | ||
int ans = 0; | ||
for(int i=N-1; i>=0; i--) { | ||
ans += (val*brr[i]); | ||
val *= 10; | ||
} | ||
return ans; | ||
} | ||
public static int[] copyArray(int brr[]) { | ||
int[] tmp = new int[N]; | ||
for(int i=0; i<N; i++) { | ||
tmp[i] = brr[i]; | ||
} | ||
return tmp; | ||
} | ||
public static int[] swapArray(int[] brr, int i, int j) { | ||
int[] trr = copyArray(brr); | ||
int tmp = trr[i]; | ||
trr[i] = trr[j]; | ||
trr[j] = tmp; | ||
|
||
return trr; | ||
} | ||
public static void dijkstra() { | ||
PriorityQueue<Node> pq = new PriorityQueue<>(); | ||
|
||
int num = arrayToInt(orr); | ||
cMap.put(num, 0); | ||
pq.add(new Node(copyArray(orr), num, 0)); | ||
|
||
while(!pq.isEmpty()) { | ||
Node now = pq.poll(); | ||
|
||
for(int i=0; i<M; i++) { | ||
int[] next = swapArray(now.arr, crr[i][0], crr[i][1]); | ||
int nextNum = arrayToInt(next); | ||
|
||
if(cMap.getOrDefault(nextNum, Integer.MAX_VALUE) > now.cost+crr[i][2]) { | ||
cMap.put(nextNum, now.cost+crr[i][2]); | ||
pq.add(new Node(next, nextNum, now.cost+crr[i][2])); | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
160 changes: 160 additions & 0 deletions
CodeTree/2019-2020년/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,160 @@ | ||
package day1126; | ||
|
||
import java.io.*; | ||
import java.util.*; | ||
|
||
public class JY_생명과학부_랩_인턴 { | ||
|
||
static int N, M, K; | ||
static List<Mold> mList; | ||
static boolean[] isDied; | ||
// 상, 하, 우, 좌 | ||
static int[] dx = {-1, 1, 0, 0}; | ||
static int[] dy = {0, 0, 1, -1}; | ||
static int total; | ||
static class Mold implements Comparable<Mold> { | ||
int num, x, y, s, d, size; | ||
|
||
public Mold(int num, int x, int y, int s, int d, int size) { | ||
super(); | ||
this.num = num; | ||
this.x = x; | ||
this.y = y; | ||
this.s = s; | ||
this.d = d; | ||
this.size = size; | ||
} | ||
|
||
@Override | ||
public int compareTo(Mold other) { | ||
// 열 -> 행의 오름차순 | ||
if(this.y == other.y) { | ||
return this.x - other.x; | ||
} | ||
return this.y - other.y; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Mold [num=" + num + ", x=" + x + ", y=" + y + ", s=" + s + ", d=" + d + ", size=" + size + "]"; | ||
} | ||
|
||
} | ||
|
||
public static void main(String[] args) throws IOException{ | ||
System.setIn(new FileInputStream("src/day1126/mold.txt")); | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
|
||
N = Integer.parseInt(st.nextToken()); | ||
M = Integer.parseInt(st.nextToken()); | ||
K = Integer.parseInt(st.nextToken()); | ||
|
||
mList = new ArrayList<>(); | ||
for(int k=1; k<K+1; k++) { | ||
st = new StringTokenizer(br.readLine()); | ||
|
||
int x = Integer.parseInt(st.nextToken()); | ||
int y = Integer.parseInt(st.nextToken()); | ||
int s = Integer.parseInt(st.nextToken()); | ||
int d = Integer.parseInt(st.nextToken()); | ||
int b = Integer.parseInt(st.nextToken()); | ||
mList.add(new Mold(k, x, y, s, d-1, b)); | ||
} | ||
|
||
isDied = new boolean[K+1]; | ||
|
||
total = 0; | ||
for(int m=1; m<M+1; m++) { | ||
// 1) 곰팡이 채취 | ||
selectMold(m); | ||
|
||
// 2) 곰팡이 움직이기 | ||
moveMold(); | ||
|
||
// 살아있는 곰팡이 재정비 | ||
aliveMold(); | ||
} | ||
|
||
System.out.println(total); | ||
|
||
} | ||
public static void selectMold(int col) { | ||
Collections.sort(mList); | ||
|
||
for(Mold m: mList) { | ||
// 이전 열 | ||
if(m.y < col) continue; | ||
// 다음 열 | ||
if(m.y > col) break; | ||
|
||
// 현재 열 : 곰팡이 채취 | ||
isDied[m.num] = true; | ||
total += m.size; | ||
break; | ||
} | ||
} | ||
public static boolean inRange(int x, int y) { | ||
return x>0 && x<=N && y>0 && y<=M; | ||
} | ||
public static int changeDir(int dir) { | ||
if(dir == 0) return 1; | ||
else if(dir == 1) return 0; | ||
else if(dir == 2) return 3; | ||
else return 2; | ||
} | ||
public static int findSize(int num) { | ||
for(Mold m: mList) { | ||
if(isDied[m.num]) continue; | ||
if(m.num == num) return m.size; | ||
} | ||
return -1; | ||
} | ||
public static void moveMold() { | ||
int[][] visited = new int[N+1][M+1]; | ||
|
||
for(Mold m : mList) { | ||
if(isDied[m.num]) continue; | ||
|
||
// 곰팡이 움직이기 | ||
int tx = m.x; | ||
int ty = m.y; | ||
for(int i=0; i<m.s; i++) { | ||
int nx = tx + dx[m.d]; | ||
int ny = ty + dy[m.d]; | ||
// 범위 벗어나면 방항 전환후 다시 진행 | ||
if(!inRange(nx, ny)) { | ||
m.d = changeDir(m.d); | ||
nx = tx + dx[m.d]; | ||
ny = ty + dy[m.d]; | ||
} | ||
tx = nx; | ||
ty = ny; | ||
} | ||
m.x = tx; | ||
m.y = ty; | ||
// 이동한 곳에 다른 곰팡이 존재함 | ||
if(visited[m.x][m.y] != 0) { | ||
int other = findSize(visited[m.x][m.y]); | ||
if(other > m.size) { | ||
isDied[m.num] = true; | ||
} else { | ||
isDied[visited[m.x][m.y]] = true; | ||
visited[m.x][m.y] = m.num; | ||
} | ||
} | ||
else { | ||
visited[m.x][m.y] = m.num; | ||
} | ||
} | ||
} | ||
public static void aliveMold() { | ||
List<Mold> tmp = new ArrayList<>(); | ||
for(Mold m : mList) { | ||
if(isDied[m.num]) continue; | ||
tmp.add(m); | ||
} | ||
mList = tmp; | ||
} | ||
|
||
} |
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.