-
Notifications
You must be signed in to change notification settings - Fork 4
[28주차] 배수빈 #361
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
Closed
[28주차] 배수빈 #361
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
53 changes: 53 additions & 0 deletions
BOJ/15001-20000번/SB_17951.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,53 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.StringTokenizer; | ||
|
||
// 최솟값의 최댓값 구하기 | ||
public class SB_17951 { | ||
static int N, K; | ||
static int[] arr; | ||
|
||
private static boolean canDiv(int target) { | ||
int cnt = 0; | ||
int sum = 0; | ||
for (int a : arr) { | ||
sum+=a; | ||
if (sum >= target) { | ||
cnt++; | ||
sum = 0; | ||
} | ||
} | ||
return cnt >= K; | ||
} | ||
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()); | ||
K = Integer.parseInt(st.nextToken()); | ||
|
||
arr = new int[N]; | ||
int mx = 0; | ||
st = new StringTokenizer(br.readLine()); | ||
for (int i = 0; i < N; i++) { | ||
arr[i] = Integer.parseInt(st.nextToken()); | ||
mx += arr[i]; | ||
} | ||
|
||
int l = 0; | ||
int h = mx; | ||
int ans = 0; | ||
while (l <= h) { | ||
int mid = (l + h) / 2; | ||
if (canDiv(mid)) { | ||
ans = mid; | ||
l = mid+1; | ||
}else { | ||
h = mid-1; | ||
} | ||
} | ||
System.out.println(ans); | ||
} | ||
|
||
} |
102 changes: 102 additions & 0 deletions
BOJ/5001-10000번/SB_9694.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.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.*; | ||
|
||
public class SB_9694 { | ||
static ArrayList<ArrayList<Node>> adj; | ||
static int[] dist; | ||
static int[] path; | ||
static Integer INF = 987654321; | ||
|
||
private static int[] dijsktra(int M) { | ||
dist[0] = 0; | ||
|
||
PriorityQueue<Node> pq = new PriorityQueue<>(); | ||
pq.offer(new Node(0, 0)); | ||
|
||
while (!pq.isEmpty()) { | ||
Node cur = pq.poll(); | ||
if (cur.cost > dist[cur.idx]) continue; | ||
|
||
for (Node nxt : adj.get(cur.idx)) { | ||
if (nxt.cost + dist[cur.idx] < dist[nxt.idx]) { | ||
dist[nxt.idx] = nxt.cost + dist[cur.idx]; | ||
path[nxt.idx] = cur.idx; | ||
pq.offer(new Node(nxt.idx, dist[nxt.idx])); | ||
} | ||
} | ||
} | ||
return path; | ||
} | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer st; | ||
StringBuilder sb = new StringBuilder(); | ||
|
||
int T = Integer.parseInt(br.readLine()); | ||
|
||
int turn = 1; | ||
while (T-- > 0) { | ||
st = new StringTokenizer(br.readLine()); | ||
int N = Integer.parseInt(st.nextToken()); | ||
int M = Integer.parseInt(st.nextToken()); | ||
|
||
dist = new int[M]; | ||
Arrays.fill(dist, INF); | ||
path = new int[M]; | ||
|
||
adj = new ArrayList<>(); | ||
for (int i = 0; i < M; i++) { | ||
adj.add(new ArrayList<>()); | ||
} | ||
|
||
for (int i = 0; i < N; i++) { | ||
st = new StringTokenizer(br.readLine()); | ||
int u = Integer.parseInt(st.nextToken()); | ||
int v = Integer.parseInt(st.nextToken()); | ||
int c = Integer.parseInt(st.nextToken()); | ||
|
||
adj.get(u).add(new Node(v, c)); | ||
adj.get(v).add(new Node(u, c)); | ||
} | ||
|
||
int[] path = dijsktra(M); | ||
|
||
if (dist[M-1]==INF){ | ||
sb.append("Case #").append(turn++).append(": ").append("-1\n"); | ||
}else{ | ||
List<Integer> ans = new ArrayList<>(); | ||
int now = M-1; | ||
while (now != 0) { | ||
ans.add(now); | ||
now = path[now]; | ||
} | ||
ans.add(0); | ||
Collections.reverse(ans); | ||
|
||
sb.append("Case #").append(turn++).append(": "); | ||
for (Integer i : ans) { | ||
sb.append(i).append(" "); | ||
} | ||
sb.append('\n'); | ||
} | ||
} | ||
|
||
System.out.println(sb); | ||
} | ||
|
||
static class Node implements Comparable<Node>{ | ||
int idx, cost; | ||
|
||
Node(int idx, int cost) { | ||
this.idx = idx; | ||
this.cost = cost; | ||
} | ||
|
||
@Override | ||
public int compareTo(Node o) { | ||
return this.cost - o.cost; | ||
} | ||
} | ||
} |
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.