-
Notifications
You must be signed in to change notification settings - Fork 0
Mun: 1월 4주차 문제 풀이 #10
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
Changes from all commits
Commits
Show all changes
4 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
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,42 @@ | ||
| import java.io.*; | ||
| import java.util.*; | ||
|
|
||
| public class Mun { | ||
| public static void main(String[] args) throws IOException { | ||
| BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
| ArrayList<Integer> crane = new ArrayList<>(); | ||
| ArrayList<Integer> box = new ArrayList<>(); | ||
|
|
||
| int N = Integer.parseInt(br.readLine()); | ||
| String[] c_input = br.readLine().split(" "); | ||
| for(String c : c_input) { | ||
| crane.add(Integer.parseInt(c)); | ||
| } | ||
| int M = Integer.parseInt(br.readLine()); | ||
| String[] b_input = br.readLine().split(" "); | ||
| for(String b : b_input) { | ||
| box.add(Integer.parseInt(b)); | ||
| } | ||
|
|
||
| Collections.sort(crane, Collections.reverseOrder()); | ||
| Collections.sort(box, Collections.reverseOrder()); | ||
|
|
||
| if(crane.get(0) < box.get(0)) { | ||
| System.out.print(-1); | ||
| return; | ||
| } | ||
| int time = 0; | ||
| while(box.size() > 0) { | ||
| time++; | ||
| for(int cSize : crane) { | ||
| for(int i=0;i<box.size();i++) { | ||
| if(cSize >= box.get(i)) { | ||
| box.remove(i); | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| System.out.print(time); | ||
| } | ||
| } |
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.*; | ||
| public class Mun { | ||
| public static void main(String[] args) throws IOException { | ||
| BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
| String[] station = br.readLine().split(" "); | ||
| int xs = Integer.parseInt(station[0]); | ||
| int ys = Integer.parseInt(station[1]); | ||
| String[] train = br.readLine().split(" "); | ||
| int xe = Integer.parseInt(train[0]); | ||
| int ye = Integer.parseInt(train[1]); | ||
| int dx = Integer.parseInt(train[2]); | ||
| int dy = Integer.parseInt(train[3]); | ||
| int gcd = getGcd(dx, dy); | ||
| dx /= gcd; | ||
| dy /= gcd; | ||
| double distance = getDis(xs, xe, ys, ye); | ||
| int x = 0; | ||
| int y = 0; | ||
| while(true) { | ||
| xe += dx; | ||
| ye += dy; | ||
| double dis = getDis(xs, xe, ys, ye); | ||
| if(distance > dis) { | ||
| distance = dis; | ||
| } else { | ||
| x = xe - dx; | ||
| y = ye - dy; | ||
| break; | ||
| } | ||
| } | ||
| System.out.print(x + " " + y); | ||
| } | ||
|
|
||
| private static double getDis(int x1, int x2, int y1, int y2) { | ||
| return Math.sqrt(Math.pow((x2 - x1), 2) + Math.pow((y2 - y1), 2)); | ||
| } | ||
|
|
||
| public static int getGcd(int a, int b) { | ||
| if(b == 0) { | ||
| return a; | ||
| } | ||
| return getGcd(b, 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,37 @@ | ||
| import java.io.*; | ||
| import java.util.*; | ||
|
|
||
| public class Mun { | ||
| public static void main(String[] args) throws IOException { | ||
| BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
| int L = Integer.parseInt(br.readLine()); | ||
| int[] S = Arrays.stream(br.readLine().split(" ")) | ||
| .mapToInt(Integer::parseInt) | ||
| .sorted() | ||
| .toArray(); | ||
| int n = Integer.parseInt(br.readLine()); | ||
| int min = 0; | ||
| int max = S[L-1]; | ||
| for(int i=0;i<L;i++) { | ||
| if(S[i] >= n) { | ||
| max = S[i]; | ||
| if(i > 0) { | ||
| min = S[i-1]; | ||
| } | ||
| break; | ||
| } | ||
| } | ||
| if(min == n || max == n) { | ||
| System.out.print(0); | ||
| return; | ||
| } | ||
| int count = 0; | ||
| for(int i=min+1;i<=n;i++) { | ||
| for(int j=n;j<max;j++) { | ||
| count++; | ||
| } | ||
| } | ||
| count--; | ||
| System.out.print(count); | ||
| } | ||
| } |
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,39 @@ | ||
| class Mun { | ||
|
|
||
| public long solution(int cap, int n, int[] deliveries, int[] pickups) { | ||
| long answer = 0; | ||
| int start = getStart(deliveries, pickups, n); | ||
| while(start >= 0) { | ||
| answer+=((start+1)*2); | ||
| start = Math.max(go(start, cap, deliveries), go(start, cap, pickups)); | ||
| } | ||
| return answer; | ||
| } | ||
|
|
||
| private int go(int start, int cap, int[] arr) { | ||
| for(int i=start;i>=0;i--) { | ||
| if(arr[i] == 0) { | ||
| continue; | ||
| } | ||
| int a = arr[i]; | ||
| if(a <= cap) { | ||
| arr[i] = 0; | ||
| cap -= a; | ||
| continue; | ||
| } | ||
| arr[i]-=cap; | ||
| return i; | ||
| } | ||
| return -1; | ||
| } | ||
|
|
||
| private int getStart(int[] a1, int[] a2, int n) { | ||
| for(int i=n-1;i>=0;i--) { | ||
| if(a1[i] > 0 || a2[i] > 0) { | ||
| return i; | ||
| } | ||
| } | ||
| return -1; | ||
| } | ||
|
|
||
|
Comment on lines
+30
to
+38
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. 시작 구간을 처음부터 정해놓고 시작해서 확실히 불필요한 부분은 연산이 안들어가니까 좋은거같아요!! |
||
| } | ||
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.
해결하기 어려운 문제였던거같은데 덕분에 풀이법 배워갑니다!