-
Notifications
You must be signed in to change notification settings - Fork 4
[12주차] 이예진 #169
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주차] 이예진 #169
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0b34228
이예진: [BOJ] 28707 배열정렬_241126
yeahdy 3aab10e
이예진: [SQL] Product Price at a Given Date_241126
yeahdy 8252d54
Merge branch 'main' of https://github.com/yeahdy/AlgorithmStudy
yeahdy e7dd7a7
이예진: [CT] 생명과학부_랩_인턴_241125
yeahdy 65c48c2
chore: 이예진: [CT] 생명과학부_랩_인턴_241125 주석수정
yeahdy a773b36
이예진: [PG] 64064 불량 사용자_241127
yeahdy 8789b96
이예진: [SQL] Trips and Users_241128
yeahdy cea060c
이예진: [BOJ] 2352 반도체 설계_241127
yeahdy f0d09a3
이예진: [BOJ] 2533 사회망 서비스(SNS)_241129
yeahdy 8ca328a
이예진: [PG] 17686 파일명 정렬_241129
yeahdy 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
44 changes: 44 additions & 0 deletions
BOJ/1000-5000번/YJ_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,44 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
|
||
public class YJ_2352 { | ||
static List<Integer> lis = new ArrayList<>(); | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
int n = Integer.parseInt(br.readLine()); | ||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
//초기화 | ||
int[] connection = new int[n+1]; | ||
for(int i=1; i<n+1; i++){ | ||
connection[i] = Integer.parseInt(st.nextToken()); | ||
} | ||
|
||
lis.add(0); | ||
//LIS | ||
for(int i = 1; i<connection.length; i++){ | ||
if(lis.get(lis.size()-1) < connection[i]){ | ||
lis.add(connection[i]); //최장 증가 원소 추가 | ||
}else{ | ||
int index = binarySearch(lis.size()-1, connection[i]); | ||
lis.set(index, connection[i]); //★현재 원소가 들어갈 위치를 찾았다면 현재 원소와 가장 가깝고 큰 원소를 제거 | ||
} | ||
} | ||
int result = lis.size()-1; | ||
System.out.println(result == 0 ? 1 : result); | ||
} | ||
|
||
//타겟이 최장 증가 원소들 중 어느 위치에 들어가면 적절한지 매개변수 탐색 | ||
public static int binarySearch(int end, int target){ | ||
int start = 1; | ||
while(start < end){ | ||
int mid = (start + end)/2; //mid 가 선을 연결할 수 있는지, 없는지 | ||
if(lis.get(mid) < target){ | ||
start = mid + 1; //start 간격을 조정하면 mid 가 커진다 > 더 넓은 범위 에서 연결할 수 있는 선을 찾는다 | ||
}else{ | ||
end = mid; //end 간격을 조정하면 mid 가 작아진다 > 연결을 더 많이 할 수 있다 | ||
} | ||
} | ||
return end; | ||
} | ||
//lower bound: mid 값보다 크거나 같을때 end 는 중간값과 같은 위치에 있음 | ||
} |
45 changes: 45 additions & 0 deletions
BOJ/1000-5000번/YJ_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,45 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
|
||
public class YJ_2533 { | ||
static List<Integer>[] graph; | ||
static int[][] dp; //dp[index][0] : 얼리 아답터 X , dp[index][1] : 얼리 아답터 O | ||
static boolean[] visited; | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
int n = Integer.parseInt(br.readLine()); | ||
|
||
dp = new int[n+1][2]; | ||
visited = new boolean[n+1]; | ||
graph = new ArrayList[n+1]; | ||
for(int i = 1; i < n+1; i++) { | ||
graph[i] = new ArrayList<>(); | ||
} | ||
for(int i = 0; i < n-1; i++) { | ||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
int u = Integer.parseInt(st.nextToken()); | ||
int v = Integer.parseInt(st.nextToken()); | ||
graph[u].add(v); | ||
graph[v].add(u); | ||
} | ||
|
||
dfs(1); | ||
System.out.println(Math.min(dp[1][0], dp[1][1])); | ||
} | ||
|
||
static void dfs(int u) { | ||
visited[u] = true; | ||
dp[u][0] = 0; //얼리 아답터 X | ||
dp[u][1] = 1; //얼리 아답터 O | ||
|
||
for(int i=0; i<graph[u].size(); i++) { | ||
if(graph[u].get(i) == null || visited[graph[u].get(i)]) { //연결된 친구가 없거나, 이미 친구를 방문했다면 패스 | ||
continue; | ||
} | ||
dfs(graph[u].get(i)); | ||
dp[u][0] += dp[graph[u].get(i)][1]; //얼리어답터가 아니라면 나와 연결된 노드는 모두 얼리어답터O | ||
dp[u][1] += Math.min(dp[graph[u].get(i)][1],dp[graph[u].get(i)][0]); //얼리어답터라면 나와 연결된 노드는 얼리어답터O or 얼리어답터X | ||
} | ||
} | ||
|
||
} |
129 changes: 129 additions & 0 deletions
BOJ/30000-35000번/YJ_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,129 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
|
||
//2 <= N <= 8 으로 조합 경우의 수 8! > 40320개 | ||
//1 <= A <= 10 | ||
public class YJ_28707 { | ||
static class Controller { | ||
int l; | ||
int r; | ||
int c; | ||
|
||
public Controller(int l, int r, int c) { | ||
this.l = l; | ||
this.r = r; | ||
this.c = c; | ||
} | ||
} | ||
|
||
static class Node implements Comparable<Node>{ | ||
int v; | ||
int c; | ||
|
||
public Node(int v, int c) { | ||
this.v = v; | ||
this.c = c; | ||
} | ||
|
||
@Override | ||
public int compareTo(Node o){ | ||
return this.c - o.c; | ||
} | ||
} | ||
|
||
static int n; | ||
static int answer; | ||
static List<Controller> list = new ArrayList<>(); | ||
static Map<Integer,Integer> table = new HashMap<>(); //<배열,최단거리> 저장 테이블 | ||
static PriorityQueue<Node> pq = new PriorityQueue<>(); | ||
|
||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
n = Integer.parseInt(br.readLine()); | ||
|
||
//배열 입력값 초기화 | ||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
StringBuilder sb = new StringBuilder(); | ||
int[] arr = new int[n]; | ||
for(int i=0; i<n; i++){ | ||
arr[i] = Integer.parseInt(st.nextToken()); | ||
sb.append(arr[i]); | ||
} | ||
|
||
//★정렬하는 배열 전체를 하나의 노드 단위로 생각 | ||
int original = Integer.parseInt(sb.toString()); | ||
//비내림차순 정렬 정답 저장 | ||
Arrays.sort(arr); | ||
answer = arrToInt(arr); | ||
|
||
//조작 입력값 초기화 | ||
int m = Integer.parseInt(br.readLine()); | ||
for(int i=0; i<m; i++){ | ||
st = new StringTokenizer(br.readLine()); | ||
int l = Integer.parseInt(st.nextToken())-1; | ||
int r = Integer.parseInt(st.nextToken())-1; | ||
int c = Integer.parseInt(st.nextToken()); | ||
list.add(new Controller(l,r,c)); | ||
} | ||
|
||
table.put(original,0); | ||
pq.offer(new Node(original,0)); | ||
dijkstra(); | ||
System.out.println(table.getOrDefault(answer,-1)); | ||
} | ||
|
||
public static void dijkstra(){ | ||
while(!pq.isEmpty()){ | ||
Node node = pq.poll(); | ||
if(answer == node.v){ | ||
break; | ||
} | ||
//신규 비용이 기존 비용보다 더 클 경우 갱신불가 | ||
if(table.containsKey(node.v) && table.get(node.v) < node.c){ | ||
continue; | ||
} | ||
for(Controller controller : list){ | ||
int next = swap(node.v, controller); | ||
int cost = node.c + controller.c; | ||
if(table.containsKey(next) && table.get(next) <= cost){ | ||
continue; | ||
} | ||
//기존 비용+이동비용 이 기존의 최소 비용보다 더 작을 경우 최단거리(비용) 갱신 | ||
table.put(next,cost); | ||
pq.offer(new Node(next,cost)); | ||
} | ||
} | ||
} | ||
|
||
private static int swap(int v, Controller controller){ | ||
int[] arr = new int[n]; | ||
for(int i = n - 1; i >= 0; i--) { | ||
if(v % 10 == 0){ // 10,20,30.. 등의 두 자릿수 배수가 있다는 뜻 (ex. 1410) | ||
arr[i] = v % 100; //두 자릿수를 배열에 저장 | ||
v /= 100; | ||
} else{ //단일 자릿수일 경우 기존 자릿수 유지 | ||
arr[i] = v % 10; | ||
v /= 10; | ||
} | ||
} | ||
|
||
//조작에 맞춰서 자리 교체 | ||
int l = controller.l; | ||
int r = controller.r; | ||
int temp = arr[l]; | ||
arr[l] = arr[r]; | ||
arr[r] = temp; | ||
|
||
return arrToInt(arr); | ||
} | ||
|
||
static StringBuilder sb = new StringBuilder(); | ||
private static int arrToInt(int[] arr) { | ||
for(int num : arr){ | ||
sb.append(num); | ||
} | ||
int result = Integer.parseInt(sb.toString()); | ||
sb.setLength(0); | ||
return result; | ||
} | ||
} |
131 changes: 131 additions & 0 deletions
CodeTree/2019-2020년/YJ_생명과학부_랩_인턴.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,131 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
|
||
//2 ≤ n, m ≤ 100 > 10^4 | ||
public class YJ_생명과학부_랩_인턴 { | ||
static class Mold { | ||
int x; | ||
int y; | ||
int s; //이동거리 | ||
int d; //이동방향 | ||
int b; //곰팡이 크기 | ||
|
||
Mold(int x, int y, int s, int d, int b){ | ||
this.x = x; | ||
this.y = y; | ||
this.s = calculateS(s,d); | ||
this.d = d; | ||
this.b = b; | ||
} | ||
|
||
private int calculateS(int s, int d){ | ||
if(d<=1){ | ||
return s % (2*n-2); | ||
}else{ | ||
return s % (2*m-2); | ||
} | ||
} | ||
|
||
public void changeD(){ | ||
//위(0)↔아래(1) , 오른쪽(2)↔왼쪽(3) | ||
this.d = this.d%2 == 0? this.d+1 : this.d-1; | ||
} | ||
|
||
public boolean isBiggerThan(Mold m){ | ||
if(Objects.isNull(m)){ | ||
return true; | ||
} | ||
return this.b > m.b; | ||
} | ||
} | ||
|
||
static Mold[][] lab; | ||
static List<Mold> inventory = new ArrayList<>(); //인턴이 채취한 곰팡이들 | ||
static int n; | ||
static int m; | ||
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()); | ||
int k = Integer.parseInt(st.nextToken()); | ||
|
||
if(k == 0){ | ||
System.out.println(0); | ||
}else{ | ||
lab = new Mold[n][m]; | ||
for(int i=0; i<k; i++){ | ||
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()); | ||
lab[x-1][y-1] = new Mold(x-1,y-1,s,d-1,b); | ||
} | ||
|
||
//모든 열 검사 | ||
for(int i=0; i<m; i++){ | ||
search(i); | ||
moveMolds(); | ||
} | ||
//인턴이 채취한 곰팡이 크기 | ||
System.out.println(inventory.stream().mapToInt(mold -> mold.b).sum()); | ||
} | ||
} | ||
|
||
//곰팡이 채취하기 | ||
//열의 위에서 아래로 내려가며 탐색할 때 제일 빨리 발견한 곰팡이를 채취 | ||
public static void search(int j){ | ||
for(int i=0; i<n; i++){ | ||
Mold mold = lab[i][j]; | ||
if(!Objects.isNull(mold)){ | ||
inventory.add(mold); | ||
lab[i][j] = null; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
//곰팡이 이동 | ||
public static void moveMolds(){ | ||
Mold[][] tempLab = new Mold[n][m]; | ||
for(int i=0; i<n; i++){ | ||
for(int j=0; j<m; j++){ | ||
Mold mold = lab[i][j]; | ||
if(Objects.isNull(mold)){ | ||
continue; | ||
} | ||
Mold movedMold = move(mold); //곰팡이 움직이기 | ||
//기존 곰팡이보다 더 클 경우 기존 곰팡이 제거 | ||
if(movedMold.isBiggerThan(tempLab[movedMold.x][movedMold.y])){ | ||
tempLab[movedMold.x][movedMold.y] = movedMold; | ||
} | ||
} | ||
} | ||
//tempLab > lab 으로 옮기기 : 기존의 lab 에서 곰팡이를 이동시키면 중복 이동이 발생할 수도 있음 | ||
lab = tempLab; | ||
} | ||
|
||
private static Mold move(Mold mold){ | ||
//위 아래 오른쪽 왼쪽 | ||
int[] nx = {-1,1,0,0}; | ||
int[] ny = {0,0,1,-1}; | ||
//거리만큼 이동 | ||
int tempS = mold.s; | ||
while(tempS-- > 0){ | ||
int x = mold.x + nx[mold.d]; | ||
int y = mold.y + ny[mold.d]; | ||
//격자 범위를 벗어날 경우 방향전환 | ||
if(x < 0 || y < 0 || x >= n || y >= m){ | ||
mold.changeD(); | ||
mold.x = mold.x + nx[mold.d]; | ||
mold.y = mold.y + ny[mold.d]; | ||
}else{ //격자 범위 내일 경우 그대로 이동 | ||
mold.x = x; | ||
mold.y = y; | ||
} | ||
} | ||
return mold; | ||
} | ||
} |
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.