-
Notifications
You must be signed in to change notification settings - Fork 0
Mun: 2월 1주차 문제 풀이 #13
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
+208
−0
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,36 @@ | ||
| 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 N = Integer.parseInt(br.readLine()); | ||
| ArrayList<int[]> list = new ArrayList<>(); | ||
| for(int i=0;i<N;i++) { | ||
| String[] input = br.readLine().split(" "); | ||
| int[] score = new int[3]; | ||
| for(int j=0;j<3;j++) { | ||
| score[j] = Integer.parseInt(input[j]); | ||
| } | ||
| list.add(score); | ||
| } | ||
| list.sort((o1, o2) -> { | ||
| return o2[2] - o1[2]; | ||
| }); | ||
| StringBuilder sb = new StringBuilder(""); | ||
| int[] check = new int[N+1]; | ||
| int count = 1; | ||
| for(int[] arr : list) { | ||
| if(count == 3 && check[arr[0]] == 2) { | ||
| continue; | ||
| } | ||
| check[arr[0]]++; | ||
| sb.append(arr[0]).append(" ").append(arr[1]).append("\n"); | ||
| count++; | ||
| if(count > 3) { | ||
| break; | ||
| } | ||
| } | ||
| System.out.print(sb.toString()); | ||
| } | ||
| } |
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,29 @@ | ||
| 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 N = Integer.parseInt(br.readLine()); | ||
| HashSet<Long> set = new HashSet<>(); | ||
| for(int i=0;i<N;i++) { | ||
| set.add(Long.parseLong(br.readLine())); | ||
| } | ||
| Iterator<Long> iterator = set.iterator(); | ||
| int min = 4; | ||
| while(iterator.hasNext()) { | ||
| long num = iterator.next(); | ||
| int p = 4; | ||
| for(long i=num+1;i<num+5;i++) { | ||
| if(set.contains(i)) { | ||
| p--; | ||
| } | ||
| } | ||
| min = Math.min(min, p); | ||
| if(min == 0) { | ||
| break; | ||
| } | ||
| } | ||
| System.out.print(min); | ||
| } | ||
| } |
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,64 @@ | ||
| import java.io.*; | ||
| import java.util.*; | ||
|
|
||
| public class Mun { | ||
| static int[][] cogwheel = new int[4][8]; | ||
|
|
||
| public static void main(String[] args) throws IOException { | ||
| BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
| for(int i=0;i<4;i++) { | ||
| String[] input = br.readLine().split(""); | ||
| for(int j=0;j<8;j++) { | ||
| cogwheel[i][j] = Integer.parseInt(input[j]); | ||
| } | ||
| } | ||
| int K = Integer.parseInt(br.readLine()); | ||
| for(int i=0;i<K;i++) { | ||
| String[] input = br.readLine().split(" "); | ||
| int cr = Integer.parseInt(input[0]) - 1; | ||
| int dr = Integer.parseInt(input[1]); | ||
| int[] change = new int[4]; | ||
| change[cr] = dr; | ||
| Queue<Integer> que = new LinkedList<>(); | ||
| que.add(cr); | ||
| while(que.size() > 0) { | ||
| int now = que.poll(); | ||
| if(now > 0 && change[now-1] == 0 && (cogwheel[now][6] != cogwheel[now-1][2])) { | ||
| change[now-1] = change[now] * -1; | ||
| que.add(now-1); | ||
| } | ||
| if(now < 3 && change[now+1] == 0 && (cogwheel[now][2] != cogwheel[now+1][6])) { | ||
| change[now+1] = change[now] * -1; | ||
| que.add(now+1); | ||
| } | ||
| } | ||
| for(int j=0;j<4;j++) { | ||
| Rotation(j, change[j]); | ||
| } | ||
| } | ||
|
|
||
| int[] score = {1, 2, 4, 8}; | ||
| int sum = 0; | ||
| for(int i=0;i<4;i++) { | ||
| if(cogwheel[i][0] == 1) { | ||
| sum+=score[i]; | ||
| } | ||
| } | ||
| System.out.print(sum); | ||
| } | ||
|
|
||
| private static void Rotation(int num, int dir) { | ||
| if(dir == 0) { | ||
| return; | ||
| } | ||
| int[] copy = cogwheel[num].clone(); | ||
| int w = (dir > 0) ? -1 : 1; | ||
| for(int i=0;i<8;i++) { | ||
| int nuwD = i+w; | ||
| if(nuwD < 0) { | ||
| nuwD = 7; | ||
| } | ||
| cogwheel[num][i] = copy[nuwD%8]; | ||
| } | ||
| } | ||
| } | ||
|
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. 객체 생성해서 문제 해결하신게 인상 깊었습니다!! 저도 추후 문제 풀때 객체를 활용해보는걸 도전해보겠습니다 😊 |
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,79 @@ | ||
| import java.util.*; | ||
|
|
||
| class Mun { | ||
|
|
||
| class Robot { | ||
| int r, c, nextIdx; | ||
| boolean exited; | ||
|
|
||
| public Robot(int r, int c, int nextIdx, boolean exited) { | ||
| this.r = r; | ||
| this.c = c; | ||
| this.nextIdx = nextIdx; | ||
| this.exited = exited; | ||
| } | ||
| } | ||
|
|
||
| public int solution(int[][] points, int[][] routes) { | ||
| int n = routes.length; | ||
| Robot[] robots = new Robot[n]; | ||
|
|
||
| for (int i=0;i<n;i++) { | ||
| int[] start = points[routes[i][0] - 1]; | ||
| robots[i] = new Robot(start[0], start[1], 1, false); | ||
| } | ||
|
|
||
| int danger = 0; | ||
|
|
||
| while (true) { | ||
| Map<Integer, Integer> count = new HashMap<>(); | ||
| boolean allExited = true; | ||
|
|
||
| for(Robot rb : robots) { | ||
| if(rb.exited) { | ||
| continue; | ||
| } | ||
|
|
||
| allExited = false; | ||
| int key = rb.r * 1000 + rb.c; | ||
| count.put(key, count.getOrDefault(key, 0) + 1); | ||
| } | ||
|
|
||
| for(int v : count.values()) { | ||
| if(v >= 2) { | ||
| danger++; | ||
| } | ||
| } | ||
|
|
||
| if(allExited) { | ||
| break; | ||
| } | ||
|
|
||
| for (int i = 0; i < n; i++) { | ||
| Robot rb = robots[i]; | ||
| if(rb.exited) { | ||
| continue; | ||
| } | ||
|
|
||
| if(rb.nextIdx == routes[i].length) { | ||
| rb.exited = true; | ||
| continue; | ||
| } | ||
|
|
||
| int[] target = points[routes[i][rb.nextIdx] - 1]; | ||
|
|
||
| if (rb.r != target[0]) { | ||
| rb.r += rb.r < target[0] ? 1 : -1; | ||
| } else if (rb.c != target[1]) { | ||
| rb.c += rb.c < target[1] ? 1 : -1; | ||
| } | ||
|
|
||
| if (rb.r == target[0] && rb.c == target[1]) { | ||
| rb.nextIdx++; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return danger; | ||
| } | ||
| } |
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.
Queue 자료구조를 이용한 새로운 접근 방식을 배워갑니다!