Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions 02월/1주차/[BOJ] 아시아 정보올림피아드/Mun.java
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());
}
}
29 changes: 29 additions & 0 deletions 02월/1주차/[BOJ] 올바른 배열/Mun.java
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);
}
}
64 changes: 64 additions & 0 deletions 02월/1주차/[BOJ] 톱니바퀴/Mun.java
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<>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Queue 자료구조를 이용한 새로운 접근 방식을 배워갑니다!

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];
}
}
}
79 changes: 79 additions & 0 deletions 02월/1주차/[PRGRMS] 충돌위험 찾기/Mun.java
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

객체 생성해서 문제 해결하신게 인상 깊었습니다!! 저도 추후 문제 풀때 객체를 활용해보는걸 도전해보겠습니다 😊

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;
}
}