-
Notifications
You must be signed in to change notification settings - Fork 4
[12주차] 고다혜 #170
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
[12주차] 고다혜 #170
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0616941
고다혜: [CT] 생명과학부 랩 인턴_241125
KodaHye faf0d5d
고다혜: [SQL] Nth Highest Salary_241126
KodaHye e8991d7
fix: sql 파일 이름 변경
KodaHye c3f1825
고다혜: [BOJ] 28707 배열 정렬_241126
KodaHye 48cef12
고다혜: [PG] 64064 불량 사용자_241127
KodaHye cd8b7af
고다혜: [BOJ] 2352 반도체 설계_241127
KodaHye 5efa56e
고다혜: [PG] 17686 파일명 정렬_241129
KodaHye efb7ed4
고다혜: [BOJ] 2533 사회망 서비스(SNS)_241129
KodaHye 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
74 changes: 74 additions & 0 deletions
BOJ/1000-5000번/DH_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,74 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
|
||
/* | ||
* 반도체 설계 | ||
*/ | ||
|
||
public class DH_2352 { | ||
public static void main(String[] args) throws Exception { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer st; | ||
|
||
int n = Integer.parseInt(br.readLine()); | ||
|
||
int[] arr = new int[n]; | ||
int[] dp = new int[n]; | ||
|
||
st = new StringTokenizer(br.readLine()); | ||
for(int i = 0; i < n; i++) arr[i] = Integer.parseInt(st.nextToken()); | ||
|
||
// int result = getResultByDP(arr, dp); | ||
int result = getResultByBinarySearch(arr); | ||
|
||
System.out.println(result); | ||
} | ||
|
||
// 이분탐색을 통해 LIS의 길이 구하기 | ||
static int getResultByBinarySearch(int[] arr) { | ||
int[] lis = new int[arr.length]; | ||
|
||
int cnt = 1; | ||
|
||
lis[0] = arr[0]; | ||
|
||
for(int i = 1; i < arr.length; i++) { | ||
if(lis[cnt - 1] < arr[i]) lis[cnt++] = arr[i]; | ||
else { | ||
int idx = binarySearch(lis, arr[i], 0, cnt); | ||
lis[idx] = arr[i]; | ||
} | ||
} | ||
|
||
return cnt; | ||
} | ||
|
||
// lower bound 구하기 | ||
static int binarySearch(int[] lis, int value, int s, int e) { | ||
while(s <= e) { | ||
int m = (s + e) / 2; | ||
if(lis[m] < value) s = m + 1; | ||
else e = m - 1; | ||
} | ||
return s; | ||
} | ||
|
||
// 단순 DP를 통해 LIS 구하기 | ||
static int getResultByDP(int[] arr, int[] dp) { | ||
int result = 0; | ||
|
||
for(int i = 0; i < arr.length; i++) { | ||
dp[i] = 1; | ||
|
||
for(int j = 0; j < i; j++) { | ||
if(dp[i] < dp[j] + 1 && arr[j] < arr[i]) { | ||
dp[i] = dp[j] + 1; | ||
} | ||
} | ||
|
||
result = Math.max(result, dp[i]); | ||
} | ||
|
||
return result; | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
BOJ/1000-5000번/DH_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,89 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
|
||
/* | ||
* 사회망 서비스(SNS) | ||
*/ | ||
|
||
public class DH_2533 { | ||
static int N; | ||
static ArrayList<Integer>[] adj; | ||
static Queue<Integer> q; | ||
|
||
public static void main(String[] args) throws Exception { | ||
initInput(); | ||
solution(); | ||
} | ||
|
||
static void solution() { | ||
// 얼리 어답터가 아닌 사람은 자신의 모든 친구들이 얼리 어답터일 때만 아이디어를 받아들임 | ||
// 리프노트 구해주기 | ||
getLeafNode(); | ||
System.out.println(getEarlyAdopter()); | ||
} | ||
|
||
static int getEarlyAdopter() { | ||
int answer = 0; | ||
|
||
boolean[] v = new boolean[N + 1]; | ||
|
||
while(!q.isEmpty()) { | ||
int current = q.poll(); | ||
|
||
// 리프노드는 그냥 확인해줬다는 표시만 해주기 | ||
if(v[current]) continue; | ||
v[current] = true; | ||
|
||
// 리프노드와 이어져 있는 노드(부모) 찾기 | ||
for(int i = 0; i < adj[current].size(); i++) { | ||
int next = adj[current].get(i); // next: 부모노드 | ||
|
||
if(v[next]) continue; | ||
// 리프노드의 부모 노드는 무조건 얼리어답터가 됨 | ||
v[next] = true; | ||
answer += 1; | ||
|
||
// 부모노드(얼리어답터)에 이어져 있는 노드의 간선 모두 없애기 (부모 노드 기준 들어오는거 없애기) | ||
for(int j = 0; j < adj[next].size(); j++) { | ||
int check = adj[next].get(j); | ||
if(v[check]) continue; | ||
|
||
int removeIdx = adj[check].indexOf(next); | ||
adj[check].remove(removeIdx); | ||
|
||
// 부모 노드 기준 들어오는 간선의 시작점이 리프노드가 되었나면 리프노드 큐에 넣어주기 | ||
if(adj[check].size() == 1) q.add(check); | ||
} | ||
} | ||
} | ||
|
||
return answer; | ||
} | ||
|
||
// 리프노트 큐에 넣어주기 | ||
static void getLeafNode() { | ||
q = new ArrayDeque<Integer>(); | ||
for(int i = 1; i < adj.length; i++) { | ||
if(adj[i].size() == 1) q.add(i); | ||
} | ||
} | ||
|
||
static void initInput() throws Exception { | ||
System.setIn(new FileInputStream("./input/BOJ2533.txt")); | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer st; | ||
|
||
N = Integer.parseInt(br.readLine()); | ||
adj = new ArrayList[N + 1]; | ||
for(int i = 0; i < adj.length; i++) adj[i] = new ArrayList<Integer>(); | ||
|
||
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()); | ||
|
||
adj[a].add(b); | ||
adj[b].add(a); | ||
} | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
BOJ/30000-35000번/DH_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,102 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
|
||
/* | ||
* 배열 정렬 | ||
*/ | ||
|
||
public class DH_28707 { | ||
static final int INF = Integer.MAX_VALUE; | ||
static class Node implements Comparable<Node> { | ||
int[] arr; | ||
int c; | ||
public Node(int[] arr, int c) { | ||
this.arr = arr; | ||
this.c = c; | ||
} | ||
|
||
@Override | ||
public int compareTo(Node o) { | ||
return Integer.compare(this.c, o.c); | ||
} | ||
} | ||
static class Calculator { | ||
int l, r, c; | ||
public Calculator(int l, int r, int c) { | ||
this.l = l; | ||
this.r = r; | ||
this.c = c; | ||
} | ||
} | ||
static int N, M; | ||
static int[] A; // 초기 입력되는 배열 | ||
static HashMap<String, Integer> cost; // key: Arrays.toString(int[] arr), value: int[] arr을 만들때까지 비용 | ||
static ArrayList<Calculator> cal; // 조작에 대한 정보 저장 | ||
|
||
public static void main(String[] args) throws Exception { | ||
initInput(); | ||
solution(); | ||
} | ||
|
||
static void solution() { | ||
PriorityQueue<Node> pq = new PriorityQueue(); | ||
cost = new HashMap(); | ||
|
||
pq.add(new Node(A.clone(), 0)); | ||
cost.put(Arrays.toString(A), 0); | ||
Arrays.sort(A); // A의 비내림차순 결과 | ||
String key = Arrays.toString(A); | ||
|
||
while(!pq.isEmpty()) { | ||
Node current = pq.poll(); | ||
if(A.equals(Arrays.toString(current.arr))) break; | ||
|
||
for(Calculator ca: cal) { | ||
int[] copyArr = current.arr.clone(); | ||
int l = ca.l, r = ca.r, c = ca.c; | ||
|
||
int tmp = copyArr[l]; | ||
copyArr[l] = copyArr[r]; | ||
copyArr[r] = tmp; | ||
|
||
String nextKey = Arrays.toString(copyArr); | ||
|
||
int nextCost = current.c + c; | ||
if(!cost.containsKey(nextKey)) cost.put(nextKey, INF); | ||
if(nextCost < cost.get(nextKey)) { | ||
cost.put(nextKey, nextCost); | ||
pq.add(new Node(copyArr, nextCost)); | ||
} | ||
} | ||
} | ||
|
||
|
||
// cost의 키에 A의 비내림차순 결과가 있으면 비용 get하고, 아니라면 -1 출력 | ||
System.out.println(cost.containsKey(key) ? cost.get(key) : -1); | ||
} | ||
|
||
static void initInput() throws Exception { | ||
System.setIn(new FileInputStream("./input/BOJ28707.txt")); | ||
|
||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer st; | ||
|
||
N = Integer.parseInt(br.readLine()); | ||
A = new int[N]; | ||
|
||
st = new StringTokenizer(br.readLine()); | ||
for(int i = 0; i < A.length; i++) A[i] = Integer.parseInt(st.nextToken()); | ||
|
||
M = Integer.parseInt(br.readLine()); | ||
|
||
// 조작 list 저장 | ||
cal = new ArrayList(); | ||
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()); | ||
cal.add(new Calculator(l, r, c)); | ||
} | ||
} | ||
} |
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.