-
Notifications
You must be signed in to change notification settings - Fork 0
[ADD] choyunju 12주차 #43
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
choyunju
wants to merge
5
commits into
main
Choose a base branch
from
choyunju
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
Changes from all commits
Commits
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,57 @@ | ||
| import java.io.*; | ||
| import java.util.*; | ||
|
|
||
| class BJ_1477 { | ||
| static int[] arr; // 휴게소의 위치 배열 | ||
| static int[] diffDistance; //각 휴게소 별 거리차이 배열 | ||
| public static void main(String[] args) throws IOException { | ||
| BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); | ||
| StringTokenizer token = new StringTokenizer(reader.readLine()); | ||
| int N = Integer.parseInt(token.nextToken()); | ||
| int M = Integer.parseInt(token.nextToken()); | ||
| int L = Integer.parseInt(token.nextToken()); | ||
| //고속도로의 양 끝인 0과 L을 추가하기 위해 크기를 N+2로 지정 | ||
| arr = new int[N+2]; | ||
| arr[0] = 0; | ||
| arr[N+1] = L; | ||
| diffDistance = new int[N+1]; | ||
| token = new StringTokenizer(reader.readLine()); | ||
| for(int i=1; i<=N; i++) { | ||
| arr[i] = Integer.parseInt(token.nextToken()); | ||
| } | ||
| Arrays.sort(arr); | ||
|
|
||
| //각 휴게소 별 거리의 차이를 구한다. | ||
| for(int i=0; i<=N; i++) { | ||
| diffDistance[i] = arr[i+1] - arr[i]; | ||
| } | ||
|
|
||
|
|
||
| // 휴게소의 위치는 1~(L-1) 사이에 위치 | ||
| int left = 1; | ||
| int right = L-1; | ||
| int result = 0; | ||
|
|
||
| while(left <= right) { | ||
| int mid = (left+right)/2; | ||
| int count = 0; | ||
| for(int i=0; i<=N; i++) { | ||
| count += diffDistance[i]/mid; | ||
| // 0으로 나누어 떨어진 경우 이미 휴게소가 1개 지어진 경우이므로 -1을 해준다. | ||
| if(diffDistance[i] % mid == 0) { | ||
| count--; | ||
| } | ||
| } | ||
|
|
||
| if(count <= M) { | ||
| right = mid-1; | ||
| result = mid; | ||
| } else { | ||
| left = mid+1; | ||
|
|
||
| } | ||
| } | ||
| System.out.println(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,34 @@ | ||
| import java.io.*; | ||
| import java.util.*; | ||
|
|
||
| class BJ_20444 { | ||
| public static void main(String[] args) throws IOException { | ||
| BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); | ||
| StringTokenizer token = new StringTokenizer(reader.readLine()); | ||
| long N = Long.parseLong(token.nextToken()); | ||
| long K = Long.parseLong(token.nextToken()); | ||
|
|
||
| long left = 0; | ||
| long right = N/2; | ||
| boolean isFlag = false; | ||
| while(left <= right) { | ||
| long mid = (left+right)/2; | ||
| long count = (mid+1) * (N-mid+1); | ||
|
|
||
| if(count < K) { | ||
| left = mid+1; | ||
| } else if(count > K) { | ||
| right = mid-1; | ||
| } else { | ||
| isFlag = true; | ||
| break; | ||
|
Comment on lines
+22
to
+24
Member
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. 그냥 여기서 프린트하고 return; 해버리면 플래그를 안써도 깔끔하게 만들수 있습니다 ! |
||
| } | ||
| } | ||
|
|
||
| if(isFlag) { | ||
| System.out.println("YES"); | ||
| } else { | ||
| System.out.println("NO"); | ||
| } | ||
| } | ||
| } | ||
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,37 @@ | ||
| import java.io.*; | ||
| import java.util.*; | ||
|
|
||
| class Main { | ||
| public static void main(String[] args) throws IOException { | ||
| BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); | ||
| StringTokenizer token = new StringTokenizer(reader.readLine()); | ||
| int N = Integer.parseInt(token.nextToken()); | ||
| int M = Integer.parseInt(token.nextToken()); | ||
| int[] arr = new int[N]; | ||
| for(int i=0; i<N; i++) { | ||
| arr[i] = Integer.parseInt(reader.readLine()); | ||
| } | ||
| Arrays.sort(arr); | ||
| int left = 1; | ||
| int right = arr[N-1] - arr[0] + 1; | ||
| int result = 0; | ||
| while(left <= right) { | ||
| int mid = (left+right)/2; | ||
| int index = arr[0] + mid; | ||
| int count = 0; | ||
| for(int i=1; i<N; i++) { | ||
| if(arr[i] >= index) { | ||
| count++; | ||
| index = arr [i] + mid; | ||
| } | ||
| } | ||
| if(count >= M-1) { | ||
| left = mid+1; | ||
| result = mid; | ||
| } else { | ||
| right = mid-1; | ||
| } | ||
| } | ||
| System.out.println(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,47 @@ | ||
| import java.io.*; | ||
| import java.util.*; | ||
|
|
||
| class BJ_2470 { | ||
| static int[] arr; | ||
| static int min = Integer.MAX_VALUE; | ||
| static int a, b; | ||
|
|
||
| public static void main(String[] args) throws IOException { | ||
| BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); | ||
| int N = Integer.parseInt(reader.readLine()); | ||
| arr = new int[N]; | ||
| StringTokenizer token = new StringTokenizer(reader.readLine()); | ||
| for(int i=0; i<N; i++) { | ||
| arr[i] = Integer.parseInt(token.nextToken()); | ||
| } | ||
|
|
||
| int start = 0; | ||
| int end = N-1; | ||
| Arrays.sort(arr); | ||
| binary_search(start, end); | ||
|
|
||
| } | ||
|
|
||
| public static void binary_search(int start, int end) { | ||
| while(start < end) { | ||
| int diff = arr[start] + arr[end]; | ||
| if(min > Math.abs(diff)) { | ||
| min = Math.abs(diff); | ||
| a = arr[start]; | ||
| b = arr[end]; | ||
| } | ||
| //두 용액의 합이 음수인 경우 | ||
| if(diff < 0) { | ||
| start++; | ||
| } | ||
| //두 용액의 합이 양수인 경우 | ||
| else if(diff > 0){ | ||
| end--; | ||
| } | ||
| else { | ||
| break; | ||
| } | ||
| } | ||
|
Comment on lines
+25
to
+44
Member
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. 아 세상에.. 이렇게하면 이분탐색으로 풀리는군요! 이걸 못떠올려서 절댓값 순으로 정렬해놓고 인접한 값들만 전부 비교했습니다... 😢 |
||
| System.out.println(a + " " + b); | ||
| } | ||
| } | ||
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 @@ | ||
| import java.io.*; | ||
| import java.util.*; | ||
|
|
||
| class BJ_2473 { | ||
| public static void main(String[] args) throws IOException { | ||
| BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); | ||
| int N = Integer.parseInt(reader.readLine()); | ||
| long[] arr = new long[N]; | ||
| StringTokenizer token = new StringTokenizer(reader.readLine()); | ||
| for(int i=0; i<N; i++) { | ||
| arr[i] = Long.parseLong(token.nextToken()); | ||
| } | ||
| Arrays.sort(arr); | ||
| long a = 0; | ||
| long b = 0; | ||
| long c = 0; | ||
| long min = Long.MAX_VALUE; | ||
|
|
||
| for(int i=0; i<N-2; i++) { | ||
| long fix = arr[i]; | ||
|
|
||
| int left = i+1; | ||
| int right = N-1; | ||
| while(left<right) { | ||
|
|
||
| long sum = arr[left] + arr[right] + fix; | ||
| if(min > Math.abs(sum)) { | ||
| a = fix; | ||
| b = arr[left]; | ||
| c = arr[right]; | ||
| min = Math.abs(sum); | ||
| } | ||
|
|
||
| if(sum < 0) { | ||
| left++; | ||
| } else if(sum > 0) { | ||
| right--; | ||
| } else { | ||
| System.out.println(a + " " + b + " " + c); | ||
| System.exit(0); | ||
| } | ||
| } | ||
| } | ||
| System.out.println(a + " " + b + " " + c); | ||
| } | ||
| } |
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.
엇ㅋㅋㅋ 저는 이거를 안될때까지 뺄셈하도록 했는데 나눗셈이라는 똑똑한 방법이...