-
Notifications
You must be signed in to change notification settings - Fork 2
add solutions #216
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
Open
mjooee
wants to merge
8
commits into
main
Choose a base branch
from
hanminju
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
add solutions #216
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3620911
add solution 0328
minju-22 352f817
add solution 0329
minju-22 4f6e060
add solution 0330
minju-22 ecf7aab
add solution 0331
minju-22 f39e932
add solution 0402
minju-22 1fd219d
Merge branch 'main' of https://github.com/hitoriudon/AlgorithmStudy_JAVA
minju-22 b350107
add solution 0315
minju-22 4e5651a
add solution 0317
minju-22 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
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,62 @@ | ||
| package algorithm; | ||
|
|
||
| // 메모리: 39964 KB, 시간: 228 ms | ||
| import java.io.BufferedReader; | ||
| import java.io.InputStreamReader; | ||
| import java.util.Arrays; | ||
| import java.util.StringTokenizer; | ||
|
|
||
| public class P2110 { | ||
| static int n, c; | ||
| static int map[]; | ||
|
|
||
| public static void main(String[] args) throws Exception { | ||
| BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
| StringTokenizer st = new StringTokenizer(br.readLine()); | ||
| n = Integer.parseInt(st.nextToken()); | ||
| c = Integer.parseInt(st.nextToken()); | ||
|
|
||
| map = new int[n]; | ||
|
|
||
| for (int i = 0; i < n; i++) { | ||
| map[i] = Integer.parseInt(br.readLine()); | ||
| } | ||
|
|
||
| Arrays.sort(map); | ||
|
|
||
| int s = 1; | ||
| int e = (map[n - 1] - map[0] + 1); | ||
| int ans = 0; | ||
| while (s <= e) { | ||
| int mid = (s + e) / 2; | ||
| if (install(mid, 0, 1)) { | ||
| s = mid + 1; | ||
| if (ans < mid) { | ||
| ans = mid; | ||
| } else { | ||
| break; | ||
| } | ||
| } else { | ||
| e = mid - 1; | ||
| } | ||
| } | ||
| System.out.println(ans); | ||
| } | ||
|
|
||
| static boolean install(int dis, int prev, int cnt) { | ||
| if (cnt == c) { | ||
| return true; | ||
| } | ||
| boolean result = false; | ||
| for (int i = prev + 1; i < n; i++) { | ||
| if(n-i < c-cnt) { | ||
| return false; | ||
| } | ||
| if (map[i] - map[prev] >= dis) { | ||
| result = install(dis, i, cnt + 1); | ||
| break; | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
| } |
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,32 @@ | ||
| package algorithm; | ||
|
|
||
| // 메모리: 11712 KB, 시간: 112 ms | ||
| import java.io.BufferedReader; | ||
| import java.io.InputStreamReader; | ||
|
|
||
| public class P1300 { | ||
| public static void main(String[] args) throws Exception { | ||
| BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
| long n = Long.parseLong(br.readLine()); | ||
| long k = Long.parseLong(br.readLine()); | ||
|
|
||
| long e = n * n; | ||
| long s = 1; | ||
| while (s <= e) { | ||
| long mid = (s + e) / 2; | ||
| // System.out.println(mid); | ||
| long small = 0; | ||
| for (int i = 1; i <= n; i++) { | ||
| small += Math.min(mid / i, n); | ||
| } | ||
| if (small >= k) { | ||
| e = mid - 1; | ||
| } else { | ||
| s = mid + 1; | ||
| } | ||
| } | ||
|
|
||
| System.out.println(s); | ||
| } | ||
|
|
||
| } |
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,49 @@ | ||
| package algorithm; | ||
|
|
||
| // 메모리: 146912 KB, 시간: 564 ms | ||
| import java.io.BufferedReader; | ||
| import java.io.InputStreamReader; | ||
| import java.util.ArrayList; | ||
| import java.util.StringTokenizer; | ||
|
|
||
| public class P12015 { | ||
| static ArrayList<Integer> list = new ArrayList<Integer>(); | ||
| static int n; | ||
|
|
||
| static int find(int newVal) { | ||
| int s = 0; | ||
| int e = list.size() - 1; | ||
| if (list.isEmpty()||newVal > list.get(e) ) | ||
| return -1; | ||
| while (s <= e) { | ||
| int mid = (s + e) / 2; | ||
| if (list.get(mid) == newVal) { | ||
| return mid; | ||
| } else if (list.get(mid) < newVal) { | ||
| s = mid + 1; | ||
| } else { | ||
| e = mid - 1; | ||
| } | ||
| } | ||
| return Math.max(s, e); | ||
| } | ||
|
|
||
| public static void main(String[] args) throws Exception { | ||
| BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
| n = Integer.parseInt(br.readLine()); | ||
| StringTokenizer st = new StringTokenizer(br.readLine()); | ||
|
|
||
| for (int i = 0; i < n; i++) { | ||
| int newVal = Integer.parseInt(st.nextToken()); | ||
| int idx = find(newVal); | ||
| if (idx == -1) { | ||
| list.add(newVal); | ||
| } else { | ||
| list.set(idx, newVal); | ||
| } | ||
| } | ||
|
|
||
| System.out.println(list.size()); | ||
| } | ||
|
|
||
| } | ||
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,46 @@ | ||
| package algorithm; | ||
|
|
||
| // 메모리: 168748 KB, 시간: 668 ms | ||
| import java.io.BufferedReader; | ||
| import java.io.InputStreamReader; | ||
| import java.util.ArrayList; | ||
| import java.util.StringTokenizer; | ||
|
|
||
| public class P12738 { | ||
|
|
||
| public static void main(String[] args) throws Exception{ | ||
| BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
|
|
||
| int n = Integer.parseInt(br.readLine()); | ||
|
|
||
| StringTokenizer st = new StringTokenizer(br.readLine()); | ||
| ArrayList<Long> list = new ArrayList<>(); | ||
| while(st.hasMoreTokens()) { | ||
| long a = Integer.parseInt(st.nextToken()); | ||
|
|
||
| if(list.isEmpty() || a > list.get(list.size() - 1)) { | ||
| list.add(a); | ||
| continue; | ||
| } | ||
| int s = 0; | ||
| int e = list.size() - 1; | ||
| int idx = 0; | ||
| while(s <= e) { | ||
| int mid = (s + e) / 2; | ||
| if(list.get(mid) == a) { | ||
| idx = mid; | ||
| break; | ||
| }else if(list.get(mid) > a) { | ||
| idx = mid; | ||
| e = mid - 1; | ||
| }else { | ||
| s = mid + 1; | ||
| } | ||
| } | ||
| list.set(idx, a); | ||
| } | ||
|
|
||
| System.out.println(list.size()); | ||
| } | ||
|
|
||
| } |
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,88 @@ | ||
| package algorithm; | ||
|
|
||
| // 메모리: 47884 KB, 시간: 464 ms | ||
| import java.io.BufferedReader; | ||
| import java.io.InputStreamReader; | ||
| import java.util.HashSet; | ||
| import java.util.PriorityQueue; | ||
| import java.util.StringTokenizer; | ||
hitoriudon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| class Edge implements Comparable<Edge> { | ||
| int from; | ||
| int to; | ||
| int weight; | ||
|
|
||
| public Edge(int from, int to, int weight) { | ||
| super(); | ||
| this.from = from; | ||
| this.to = to; | ||
| this.weight = weight; | ||
| } | ||
|
|
||
| @Override | ||
| public int compareTo(Edge o) { | ||
| return this.weight - o.weight; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| public class P1197 { | ||
| static int union[]; | ||
|
|
||
| public static void main(String[] args) throws Exception { | ||
| BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
| StringTokenizer st = new StringTokenizer(br.readLine()); | ||
| int v = Integer.parseInt(st.nextToken()); | ||
| int e = Integer.parseInt(st.nextToken()); | ||
| PriorityQueue<Edge> edges = new PriorityQueue<>(); | ||
|
|
||
| for (int i = 0; i < e; i++) { | ||
| st = new StringTokenizer(br.readLine()); | ||
| int a = Integer.parseInt(st.nextToken()); | ||
| int b = Integer.parseInt(st.nextToken()); | ||
| int w = Integer.parseInt(st.nextToken()); | ||
|
|
||
| Edge newE = new Edge(a, b, w); | ||
| edges.add(newE); | ||
| } | ||
|
|
||
| int cnt = 0; | ||
| union = new int[v+1]; | ||
| for (int i = 1; i < v + 1; i++) { | ||
| union[i] = i; | ||
| } | ||
| int ans = 0; | ||
| while (true) { | ||
| Edge now = edges.poll(); | ||
| // System.out.println(now.from + " " + now.to); | ||
| if (find(now.from) == find(now.to)) | ||
| continue; | ||
| union[union[now.from]] = union[now.to]; | ||
| ans += now.weight; | ||
| cnt+=2; | ||
| if(cnt >= v) { | ||
| boolean noans = false; | ||
| for(int i = 2; i < v+1; i++) { | ||
| if(find(1) != find(i)) { | ||
| noans = true; | ||
| break; | ||
| } | ||
| } | ||
| if(!noans) { | ||
| break; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| System.out.println(ans); | ||
| } | ||
|
|
||
| private static int find(int x) { | ||
| if (union[x] == x) | ||
| return x; | ||
| else { | ||
| return union[x] = find(union[x]); | ||
| } | ||
| } | ||
|
|
||
| } | ||
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,51 @@ | ||
| package algorithm; | ||
|
|
||
| // 메모리: 51376 KB, 시간: 352ms | ||
| import java.io.BufferedReader; | ||
| import java.io.InputStreamReader; | ||
| import java.util.StringTokenizer; | ||
|
|
||
| public class P1717 { | ||
| static int u[]; | ||
|
|
||
| public static void main(String[] args) throws Exception { | ||
| 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()); | ||
| StringBuilder sb = new StringBuilder(); | ||
| u = new int[n + 1]; | ||
| for (int i = 0; i <= n; i++) { | ||
| u[i] = i; | ||
| } | ||
| for (int i = 0; i < m; i++) { | ||
| st = new StringTokenizer(br.readLine()); | ||
| int cal = Integer.parseInt(st.nextToken()); | ||
| int a = Integer.parseInt(st.nextToken()); | ||
| int b = Integer.parseInt(st.nextToken()); | ||
| if (cal == 0) { | ||
| find(a); | ||
| u[find(b)] = u[a]; | ||
| } else { | ||
| find(a); | ||
| find(b); | ||
| if (u[a] == u[b]) { | ||
| sb.append("yes"); | ||
| } else { | ||
| sb.append("no"); | ||
| } | ||
| sb.append("\n"); | ||
| } | ||
| } | ||
| System.out.println(sb); | ||
| } | ||
|
|
||
| static int find(int x) { | ||
| if (x != u[x]) { | ||
| return u[x] = find(u[x]); | ||
| } else { | ||
| return x; | ||
| } | ||
| } | ||
|
|
||
| } |
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.
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.
gdgd