-
Notifications
You must be signed in to change notification settings - Fork 4
[8주차] 이지영 #110
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
[8주차] 이지영 #110
Changes from all commits
bb6cff3
91b855b
15694c1
6f838b1
26236a1
db7f68e
7d2f318
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package day1029; | ||
|
||
import java.io.*; | ||
import java.util.*; | ||
|
||
public class JY_1911 { | ||
|
||
static int N, L; | ||
static long[][] hrr; | ||
|
||
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()); | ||
L = Integer.parseInt(st.nextToken()); | ||
|
||
hrr = new long[N][2]; | ||
for(int i=0; i<N; i++) { | ||
st = new StringTokenizer(br.readLine()); | ||
hrr[i][0] = Integer.parseInt(st.nextToken()); | ||
hrr[i][1] = Integer.parseInt(st.nextToken()); | ||
} | ||
|
||
// 물웅덩이 위치순으로 정렬 | ||
Arrays.sort(hrr, (o1, o2)->Long.compare(o1[0], o2[0])); | ||
|
||
long s = 0; | ||
long e = hrr[N-1][1]; // 최대의 널빤지수 == L이 1이고, 가장 마지막 물웅덩이까지 다 덮을 때 | ||
long cnt = 0; | ||
|
||
while(s <= e) { | ||
long mid = (s + e) / 2; | ||
|
||
if(isPossible(mid)) { | ||
cnt = mid; | ||
e = mid - 1; | ||
}else { | ||
s = mid + 1; | ||
} | ||
} | ||
|
||
System.out.println(cnt); | ||
|
||
} | ||
public static boolean isPossible(long mid) { | ||
long pre = 0; // 마지막 널빤지 위치 | ||
long total = 0; // 총 필요한 널빤지 개수 | ||
for(int i=0; i<N; i++) { | ||
long[] now = hrr[i]; | ||
// 현재 물웅덩이 시작점에 널빤지 없다면 새로운 널빤지 시작점 | ||
if(pre < now[0]) { | ||
pre = now[0]; | ||
} | ||
|
||
// 물 웅덩이 크기 | ||
long size = now[1] - pre; | ||
if(size <= 0) continue; | ||
|
||
// 필요한 널빤지 개수 | ||
long cnt = (size / L); | ||
if(size % L != 0) cnt++; | ||
total += cnt; | ||
if(total > mid) return false; | ||
|
||
pre = pre + cnt * L; // 마지막 널빤지 위치 갱신 | ||
} | ||
|
||
return true; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package day1031; | ||
|
||
import java.io.*; | ||
import java.util.*; | ||
|
||
public class JY_2461 { | ||
|
||
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 M = Integer.parseInt(st.nextToken()); | ||
|
||
int[][] srr = new int[N][M]; | ||
for(int i=0; i<N; i++) { | ||
st = new StringTokenizer(br.readLine()); | ||
for(int j=0; j<M; j++) { | ||
srr[i][j] = Integer.parseInt(st.nextToken()); | ||
} | ||
} | ||
|
||
// 각 반 정렬 | ||
for(int i=0; i<N; i++) { | ||
Arrays.sort(srr[i]); | ||
} | ||
|
||
// 각 반의 학생 인덱스 포인터 배열 | ||
int[] n = new int[N]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저는 투포인터하면 한줄배열을 떠올리게되는데, 각 반별로 포인터를 둬서 값을 비교해나가는 방법 멋있네요!👍 |
||
|
||
int ans = Integer.MAX_VALUE; | ||
while(true) { | ||
int max = Integer.MIN_VALUE; | ||
int min = Integer.MAX_VALUE; | ||
int minIdx = -1; | ||
|
||
// 각 반 반복 | ||
for(int i=0; i<N; i++) { | ||
int j = n[i]; // 각 반이 현재 가리키고 있는 학생 | ||
if(max < srr[i][j]) { | ||
max = srr[i][j]; | ||
} | ||
if(min > srr[i][j]) { | ||
min = srr[i][j]; | ||
minIdx = i; | ||
} | ||
} | ||
|
||
ans = Math.min(ans, max-min); | ||
n[minIdx]++; | ||
if(n[minIdx] == M) break; | ||
|
||
} | ||
|
||
System.out.println(ans); | ||
|
||
} | ||
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
package day1030; | ||
|
||
import java.io.*; | ||
import java.util.*; | ||
|
||
public class JY_20007 { | ||
|
||
static long INF = Long.MAX_VALUE; | ||
static int N, M, X, Y; | ||
static List<Node>[] g; | ||
static long[] distance; | ||
static class Node implements Comparable<Node> { | ||
int n; | ||
long dist; | ||
|
||
public Node(int n, long dist) { | ||
super(); | ||
this.n = n; | ||
this.dist = dist; | ||
} | ||
@Override | ||
public int compareTo(Node other) { | ||
return Long.compare(this.dist, other.dist); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Node [n=" + n + ", dist=" + 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()); | ||
M = Integer.parseInt(st.nextToken()); | ||
X = Integer.parseInt(st.nextToken()); | ||
Y = Integer.parseInt(st.nextToken()); | ||
|
||
g = new ArrayList[N]; | ||
for(int i=0; i<N; i++) { | ||
g[i] = new ArrayList<>(); | ||
} | ||
|
||
distance = new long[N]; | ||
for(int i=0; i<N; i++) { | ||
distance[i] = INF; | ||
} | ||
|
||
for(int i=0; i<M; i++) { | ||
st = new StringTokenizer(br.readLine()); | ||
int a = Integer.parseInt(st.nextToken()); | ||
int b = Integer.parseInt(st.nextToken()); | ||
int c = Integer.parseInt(st.nextToken()); | ||
g[a].add(new Node(b, c)); | ||
g[b].add(new Node(a, c)); | ||
} | ||
|
||
dijkstra(Y); | ||
|
||
Arrays.sort(distance); | ||
|
||
// System.out.println(Arrays.toString(distance)); | ||
|
||
// 갈 수없는 곳 찾기 | ||
for(int i=N-1; i>=0; i--) { | ||
if(2*distance[i] > X) { | ||
System.out.println(-1); | ||
return; | ||
} | ||
} | ||
|
||
// 투포인터 이거 왜안되죠??? | ||
// X= 21, distance = [0, 1, 1, 9, 9]이면 최소일수는 2일아닌가요??!! ㅠ0ㅠ | ||
// int s = 0; | ||
// int e = N-1; | ||
// long sum = 2*distance[e]; | ||
// while(s <= e) { | ||
// if(sum + 2*distance[s] <= X) { | ||
// sum += 2*distance[s]; | ||
// s++; | ||
// } else { | ||
// e--; | ||
// ans++; | ||
// sum = 2*distance[e]; | ||
// } | ||
// } | ||
|
||
int ans = 1; | ||
long sum = 0; | ||
for(int i=0; i<N; i++) { | ||
if(sum + 2*distance[i] > X) { | ||
ans++; | ||
sum = 2*distance[i]; | ||
} else { | ||
sum += 2*distance[i]; | ||
} | ||
} | ||
|
||
System.out.println(ans); | ||
|
||
} | ||
public static void dijkstra(int start) { | ||
distance[start] = 0; | ||
PriorityQueue<Node> pq = new PriorityQueue<>(); | ||
pq.add(new Node(start, 0)); | ||
|
||
while(!pq.isEmpty()) { | ||
Node now = pq.poll(); | ||
|
||
if(distance[now.n] < now.dist) continue; | ||
|
||
for(Node next: g[now.n]) { | ||
long cost = now.dist + next.dist; | ||
if(distance[next.n] > cost) { | ||
distance[next.n] = cost; | ||
pq.add(new Node(next.n, cost)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package day1029; | ||
|
||
import java.io.*; | ||
import java.util.*; | ||
|
||
public class JY_9342 { | ||
|
||
static boolean isOk; | ||
|
||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
|
||
int T = Integer.parseInt(br.readLine()); | ||
for(int t=0; t<T; t++) { | ||
String str = br.readLine(); | ||
|
||
isOk = false; | ||
isGen(str, 0, 0); | ||
if(!isOk) System.out.println("Good"); | ||
else System.out.println("Infected!"); | ||
} | ||
|
||
} | ||
/* | ||
* << type >> 규칙 | ||
* 0 : 문자열은 {A, B, C, D, E, F} 중 0개 또는 1개로 시작해야 한다. | ||
* 1 : 그 다음에는 A가 하나 또는 그 이상 있어야 한다. | ||
* 2 : 그 다음에는 F가 하나 또는 그 이상 있어야 한다. | ||
* 3 : 그 다음에는 C가 하나 또는 그 이상 있어야 한다. | ||
* 4 : 그 다음에는 {A, B, C, D, E, F} 중 0개 또는 1개가 있으며, 더 이상의 문자는 없어야 한다. | ||
* */ | ||
public static void isGen(String s, int idx, int type) { | ||
if(type == 0) { | ||
if(s.charAt(idx) >= 'A' && s.charAt(idx) <= 'F') { | ||
if(s.charAt(idx) == 'A') isGen(s, idx, 1); // 다음 조건도 A로 시작하므로 인덱스 증가X | ||
else isGen(s, idx+1, 1); | ||
} | ||
} else if(type == 1) { | ||
int next = check(s, idx, 'A'); | ||
if(next != -1) { | ||
isGen(s, next, 2); | ||
} | ||
} else if(type == 2) { | ||
int next = check(s, idx, 'F'); | ||
if(next != -1) { | ||
isGen(s, next, 3); | ||
} | ||
} else if(type == 3) { | ||
int next = check(s, idx, 'C'); | ||
if(next != -1) { | ||
isGen(s, next, 4); | ||
} | ||
} else { | ||
if(idx == s.length()) isOk = true; | ||
else if(idx == s.length()-1 && s.charAt(idx) >= 'A' && s.charAt(idx) <= 'F') { | ||
isOk = true; | ||
} | ||
} | ||
} | ||
public static int check(String s, int idx, char c) { | ||
int i = idx; | ||
while(i < s.length()) { | ||
if(s.charAt(i) != c) break; | ||
i++; | ||
} | ||
if(i > idx) { | ||
return i; | ||
} | ||
return -1; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import java.util.*; | ||
|
||
class Solution { | ||
public long solution(int cap, int n, int[] deliveries, int[] pickups) { | ||
long answer = 0; | ||
|
||
int i = n-1; | ||
while(i >= 0) { | ||
System.out.println("i: "+i); | ||
System.out.println("d: "+Arrays.toString(deliveries)); | ||
System.out.println("p: "+Arrays.toString(pickups)); | ||
|
||
// 배달과 수거 모두 끝난 집은 pass | ||
if(deliveries[i] ==0 && pickups[i] ==0){ | ||
i--; | ||
continue; | ||
} | ||
Comment on lines
+8
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 현재 위치를 다음 집으로 옮겨주고, 배달이나 수거를 못마친 집을 재방문하게 하는 부분이 어려웠는데, 같은 위치를 다시 방문해야 할 때는 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저도 처음에는 배달과 수거를 같이 생각했는데 문제 예시보니깐 따로 생각해야 하더라고요!! 문제를 더 잘 이해하는 것도 중요한 것 같습니다 !! ㅠㅜㅜ |
||
|
||
// 현재 가장 먼 집위치 | ||
int start = i+1; | ||
|
||
// 배달하기 | ||
int capD = cap; | ||
int d = i; | ||
while(d >= 0) { | ||
if(capD < deliveries[d]) { | ||
deliveries[d] -= capD; | ||
break; | ||
} | ||
capD -= deliveries[d]; | ||
deliveries[d] = 0; | ||
d--; | ||
} | ||
|
||
// 수거하기 | ||
int capP = cap; | ||
int p = i; | ||
while(p >= 0) { | ||
if(capP < pickups[p]) { | ||
pickups[p] -= capP; | ||
break; | ||
} | ||
capP -= pickups[p]; | ||
pickups[p] = 0; | ||
p--; | ||
} | ||
|
||
answer += (start*2); | ||
} | ||
|
||
return answer; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
-- 550. Game Play Analysis IV | ||
-- https://leetcode.com/problems/game-play-analysis-iv/?envType=study-plan-v2&envId=top-sql-50 | ||
SELECT ROUND(COUNT(DISTINCT A.player_id) / (SELECT COUNT(DISTINCT player_id) FROM activity), 2) AS fraction | ||
FROM activity A | ||
JOIN activity B | ||
on A.player_id = B.player_id | ||
WHERE (A.player_id, A.event_date) in (SELECT player_id, min(event_date) FROM activity group by player_id) AND DATEDIFF(B.event_date, A.event_date) = 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저도 매개변수 탐색을 생각하긴 했었는데 대단해여
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ㅎㅎㅎㅎ 결론은 N이 작아 그냥 풀면됐지만,,,, 이분탐색 연습한걸로,,,, ㅎㅎㅎㅎ