Skip to content

Commit 878d8ba

Browse files
committed
Merge branch 'week2'
2 parents be8ed2c + 39911d2 commit 878d8ba

6 files changed

+354
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class Main {
5+
6+
public static void main(String[] args) throws IOException {
7+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
String[] input = br.readLine().split(" ");
9+
int N = Integer.parseInt(input[0]);
10+
int K = Integer.parseInt(input[1]);
11+
Queue<Integer> q = new LinkedList<>();
12+
for(int i=1; i<=N; i++) {
13+
q.offer(i);
14+
}
15+
16+
StringBuffer sb = new StringBuffer();
17+
sb.append('<');
18+
for(int i=0; i<N; i++) {
19+
for(int j=0; j<K-1; j++) {
20+
q.offer(q.poll());
21+
}
22+
sb.append(q.poll());
23+
if(i < N-1) {
24+
sb.append(", ");
25+
}
26+
}
27+
sb.append('>');
28+
System.out.println(sb);
29+
}
30+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class Main {
5+
6+
public static int N;
7+
8+
public static void main(String[] args) throws IOException {
9+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
10+
N = Integer.parseInt(br.readLine());
11+
boolean[] arr = new boolean[N+1];
12+
StringTokenizer st = new StringTokenizer(br.readLine());
13+
for(int i=1; i<=N; i++) {
14+
arr[i] = (Integer.parseInt(st.nextToken()) == 1);
15+
}
16+
int m = Integer.parseInt(br.readLine());
17+
for(int i=0; i<m; i++) {
18+
st = new StringTokenizer(br.readLine());
19+
int student = Integer.parseInt(st.nextToken());
20+
int num = Integer.parseInt(st.nextToken());
21+
updateSwitch(arr, student, num);
22+
}
23+
StringBuffer sb = new StringBuffer();
24+
for(int i=1; i<=N; i++) {
25+
sb.append(arr[i] ? '1' : '0');
26+
if(i % 20 == 0) {
27+
sb.append('\n');
28+
}else {
29+
sb.append(' ');
30+
}
31+
}
32+
System.out.println(sb);
33+
}
34+
35+
public static void updateSwitch(boolean[] arr, int student, int num) {
36+
if(student == 1) {
37+
for(int i=1; i<=N; i++) {
38+
if(i % num == 0) {
39+
arr[i] = !arr[i];
40+
}
41+
}
42+
}else {
43+
for(int i=0; (num-i>=1) && (num+i <= N); i++) {
44+
if(arr[num-i] == arr[num+i]) {
45+
arr[num-i] = arr[num+i] = !arr[num+i];
46+
}else {
47+
return;
48+
}
49+
}
50+
}
51+
}
52+
}

week2/BOJ_13335(트럭).java

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class Main {
5+
6+
public static void main(String[] args) throws IOException {
7+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
StringTokenizer st = new StringTokenizer(br.readLine());
9+
int n = Integer.parseInt(st.nextToken());
10+
int length = Integer.parseInt(st.nextToken());
11+
int maxWeight = Integer.parseInt(st.nextToken());
12+
13+
st = new StringTokenizer(br.readLine());
14+
// [트럭 무게, 현재 위치]
15+
List<int[]> truckList = new ArrayList<>();
16+
for(int i=0; i<n; i++) {
17+
int truck = Integer.parseInt(st.nextToken());
18+
truckList.add(new int[]{truck, -1*i});
19+
}
20+
21+
int time = 0;
22+
int currentWeight = 0;
23+
int count = 0;
24+
int index = 0;
25+
while(true) {
26+
// 마지막 트럭이 다리를 건넜다면 종료
27+
if(truckList.get(n-1)[1] > length) {
28+
System.out.println(time);
29+
return;
30+
}
31+
32+
for(int i=index; i<n; i++) {
33+
int w = truckList.get(i)[0];
34+
int l = truckList.get(i)[1];
35+
if(l > 0) { // 다리 위에 있는 트럭
36+
moveTruck(truckList, i);
37+
}else if(l == 0) { // 다리 입구에 위치한 트럭
38+
// 진입 가능 트럭(무게 중량 초과 x, 다리 길이가 트럭 개수보다 작은 경우)
39+
if((currentWeight + w <= maxWeight) && (count < length)) {
40+
moveTruck(truckList, i);
41+
currentWeight += w;
42+
count++;
43+
}else {
44+
break;
45+
}
46+
}else { // 다리에 진입하지 않은 트럭
47+
moveTruck(truckList, i);
48+
}
49+
50+
// 다리를 모두 건넌 경우
51+
if(l >= length) {
52+
currentWeight -= w;
53+
count--;
54+
index++;
55+
}
56+
}
57+
time++;
58+
}
59+
}
60+
61+
public static void moveTruck(List<int[]> truckList, int index) {
62+
int[] truck = truckList.get(index);
63+
truck[1]++;
64+
truckList.set(index, truck);
65+
}
66+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class Main {
5+
6+
public static void main(String[] args) throws IOException {
7+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
StringTokenizer st = new StringTokenizer(br.readLine());
9+
int N = Integer.parseInt(st.nextToken());
10+
int M = Integer.parseInt(st.nextToken());
11+
int B = Integer.parseInt(st.nextToken());
12+
int[][] arr = new int[N][M];
13+
int max = Integer.MIN_VALUE;
14+
int min = Integer.MAX_VALUE;
15+
for(int i=0; i<N; i++) {
16+
st = new StringTokenizer(br.readLine());
17+
for(int j=0; j<M; j++) {
18+
arr[i][j] = Integer.parseInt(st.nextToken());
19+
max = Math.max(max, arr[i][j]);
20+
}
21+
}
22+
int height = 0;
23+
for(int i=0; i<=max; i++) {
24+
int stackBlock = 0;
25+
int removeBlock = 0;
26+
for(int j=0; j<N; j++) {
27+
for(int k=0; k<M; k++) {
28+
if(arr[j][k] < i) {
29+
stackBlock += i - arr[j][k];
30+
}else {
31+
removeBlock += arr[j][k] - i;
32+
}
33+
}
34+
}
35+
if(stackBlock > removeBlock + B) {
36+
continue;
37+
}
38+
int time = stackBlock + 2*removeBlock;
39+
if(min >= time) {
40+
if(min == time) {
41+
height = Math.max(height, i);
42+
}else {
43+
height = i;
44+
}
45+
min = time;
46+
}
47+
}
48+
System.out.println(min + " " + height);
49+
}
50+
}

week2/BOJ_2578(빙고).java

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class Main {
5+
6+
public static void main(String[] args) throws IOException {
7+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
int[][] board = new int[5][5];
9+
for(int i=0; i<5; i++) {
10+
StringTokenizer st = new StringTokenizer(br.readLine());
11+
for(int j=0; j<5; j++) {
12+
board[i][j] = Integer.parseInt(st.nextToken());
13+
}
14+
}
15+
int answer = 0;
16+
for(int i=0; i<5; i++) {
17+
StringTokenizer st = new StringTokenizer(br.readLine());
18+
for(int j=0; j<5; j++) {
19+
int num = Integer.parseInt(st.nextToken());
20+
removeNumber(board, num);
21+
answer++;
22+
if(isBingo(board)) {
23+
System.out.println(answer);
24+
return;
25+
}
26+
}
27+
}
28+
}
29+
30+
public static void removeNumber(int[][] board, int num) {
31+
for(int i=0; i<5; i++) {
32+
for(int j=0; j<5; j++) {
33+
if(board[i][j] == num) {
34+
board[i][j] = 0;
35+
}
36+
}
37+
}
38+
}
39+
40+
public static boolean isBingo(int[][] board) {
41+
int bingo = 0;
42+
// 가로, 세로 카운트
43+
for(int i=0; i<5; i++) {
44+
int count1 = 0;
45+
int count2 = 0;
46+
for(int j=0; j<5; j++) {
47+
if(board[i][j] == 0) {
48+
count1++;
49+
}
50+
if(board[j][i] == 0) {
51+
count2++;
52+
}
53+
}
54+
if(count1 == 5) {
55+
bingo++;
56+
}
57+
if(count2 == 5) {
58+
bingo++;
59+
}
60+
}
61+
62+
// 대각선 카운트
63+
int count1 = 0;
64+
int count2 = 0;
65+
for(int i=0; i<5; i++) {
66+
if(board[i][i] == 0) {
67+
count1++;
68+
}
69+
if(board[i][4-i] == 0) {
70+
count2++;
71+
}
72+
}
73+
if(count1 == 5) {
74+
bingo++;
75+
}
76+
if(count2 == 5) {
77+
bingo++;
78+
}
79+
return bingo >= 3;
80+
}
81+
}

week2/BOJ_2615(오목).java

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class Main {
5+
6+
public static void main(String[] args) throws IOException {
7+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
int[][] omok = new int[21][21];
9+
for(int i=1; i<=19; i++) {
10+
StringTokenizer st = new StringTokenizer(br.readLine());
11+
for(int j=1; j<=19; j++) {
12+
omok[i][j] = Integer.parseInt(st.nextToken());
13+
}
14+
}
15+
for(int i=1; i<=19; i++) {
16+
for(int j=1; j<=19; j++) {
17+
int color = omok[i][j];
18+
if(color == 0) {
19+
continue;
20+
}
21+
int count1 = 0;
22+
int count2 = 0;
23+
for(int k=0; k<5; k++) {
24+
// 세로
25+
if(i+k <= 19) {
26+
if(omok[i][j] == omok[i+k][j]) {
27+
count1++;
28+
}
29+
}
30+
// 가로
31+
if(j+k <= 19) {
32+
if(omok[i][j] == omok[i][j+k]) {
33+
count2++;
34+
}
35+
}
36+
}
37+
if((count1 == 5 && omok[i+5][j] != color && omok[i-1][j] != color)
38+
|| (count2 == 5 && omok[i][j+5] != color && omok[i][j-1] != color)) {
39+
System.out.println(color);
40+
System.out.println(i + " " + j);
41+
return;
42+
}
43+
44+
count1 = 0;
45+
count2 = 0;
46+
for(int k=0; k<5; k++) {
47+
// 오른쪽 위 대각선
48+
if(j-k >= 1 && i+k <= 19) {
49+
if(omok[i][j] == omok[i+k][j-k]) {
50+
count1++;
51+
}
52+
}
53+
// 오른쪽 아래 대각선
54+
if(i+k <= 19 && j+k <= 19) {
55+
if(omok[i][j] == omok[i+k][j+k]) {
56+
count2++;
57+
}
58+
}
59+
}
60+
if(count1 == 5 && omok[i+5][j-5] != color && omok[i-1][j+1] != color) {
61+
System.out.println(color);
62+
System.out.println((i+4) + " " + (j-4));
63+
return;
64+
}
65+
66+
if(count2 == 5 && omok[i+5][j+5] != color && omok[i-1][j-1] != color) {
67+
System.out.println(color);
68+
System.out.println(i + " " + j);
69+
return;
70+
}
71+
}
72+
}
73+
System.out.println("0");
74+
}
75+
}

0 commit comments

Comments
 (0)