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
40 changes: 40 additions & 0 deletions 02월/1주차/[BOJ] 아시아 정보올림피아드/Min.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

class Min {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
List<int[]> list = new ArrayList<>();
for(int i = 0; i < N; i++) {
StringTokenizer str = new StringTokenizer(br.readLine());
int c = Integer.parseInt(str.nextToken());
int stu = Integer.parseInt(str.nextToken());
int score = Integer.parseInt(str.nextToken());

list.add(new int[]{c, stu, score});
}

list.sort((a, b) -> b[2]- a[2]);
int[] countryCnt = new int[101];
int cnt = 0;
StringBuilder sb = new StringBuilder();

for(int i = 0; i < list.size(); i++) {
if(cnt == 3) break;
int[] cur = list.get(i);
int countryIdx = cur[0];
if(countryCnt[countryIdx] < 2) {
sb.append(cur[0]).append(" ").append(cur[1]).append("\n");
countryCnt[countryIdx] += 1;
cnt += 1;
}
}

System.out.println(sb);
}
}
35 changes: 35 additions & 0 deletions 02월/1주차/[BOJ] 올바른 배열/Min.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Min {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
List<Integer> list = new ArrayList<>();
for(int i = 0; i < N; i++) {
list.add(Integer.parseInt(br.readLine()));
}

Collections.sort(list);
int answer = 4;
for(int i = 0; i < list.size(); i++) {
int num = list.get(i);
int need = 4;
for(int j = 0; j < 4; j++) {
if(list.contains(++num)) {
need -= 1;
}
}

answer = Math.min(answer, need);
}

System.out.println(answer);


}
}
85 changes: 85 additions & 0 deletions 02월/1주차/[BOJ] 톱니바퀴/Min.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Min {
static String[][] wheels;
static int[] rotate;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
wheels = new String[4][8];
for(int i = 0; i < 4; i++) {
wheels[i] = br.readLine().split("");
}

int K = Integer.parseInt(br.readLine());
for(int i = 0; i < K; i++) {
StringTokenizer str = new StringTokenizer(br.readLine());
int wheel = Integer.parseInt(str.nextToken()) - 1;
int dir = Integer.parseInt(str.nextToken());
rotate = new int[4];
rotate[wheel] = dir;

changeLeft(wheel, dir);
changeRight(wheel, dir);

for(int j = 0; j < 4; j++) {
if(rotate[j] == 1) {
rotateRight(j);
} else if(rotate[j] == -1){
rotateLeft(j);
}
}
}
int score = getScore();
System.out.println(score);
}

private static void rotateRight(int idx) {
String tmp = wheels[idx][7];
for(int i = 7; i > 0; i--) {
wheels[idx][i] = wheels[idx][i - 1];
}
wheels[idx][0] = tmp;
}

private static void rotateLeft(int idx) {
String tmp = wheels[idx][0];
for(int i = 0; i < 7; i++) {
wheels[idx][i] = wheels[idx][i + 1];
}
wheels[idx][7] = tmp;
}

private static void changeLeft(int idx, int dir) {
if(idx == 0) return;
if(!wheels[idx][6].equals(wheels[idx - 1][2])) {
rotate[idx - 1] = -dir;
changeLeft(idx - 1, -dir);
Copy link
Member

Choose a reason for hiding this comment

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

이렇게 변수 앞에 - 만 붙여도 변환이 가능했네요! 배워갑니다! 👍

}
}

private static void changeRight(int idx, int dir) {
if(idx == 3) return;
if(!wheels[idx][2].equals(wheels[idx + 1][6])) {
rotate[idx + 1] = -dir;
changeRight(idx + 1, -dir);
}
}

private static int getScore() {
int sum = 0;
int plus = 1;
for(int i = 0; i < 4; i++) {
if(wheels[i][0].equals("1")) {
sum += plus;
}
plus *= 2;
Copy link
Member

Choose a reason for hiding this comment

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

이렇게 점수 규칙을 파악해서 배열 생성 없이도 잘 계산할 수 있었네요! 👍

}

return sum;
}


}