Skip to content
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

엄소현 / 10월 3주차 / 목 #286

Merged
merged 11 commits into from
Oct 20, 2023
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
42 changes: 42 additions & 0 deletions EomSoHyun/BOJ/boj15989.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

static int[][] dp;

public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();

int T = Integer.parseInt(br.readLine());

for (int t = 1; t <= T; t++) {
int n = Integer.parseInt(br.readLine());
dp = new int[4][n+1];

for (int i = 0; i < 4; i++) {
dp[i][0] = 1;
}
for (int i = 0; i < n+1; i++) {
dp[1][i] = 1;
}

for (int i = 2; i <= 3; i++) {
for (int j = 1; j <= n; j++) {
dp[i][j] = dp[i-1][j]; // i 선택 X
if (j-i >= 0) {
dp[i][j] += dp[i][j-i];
}
}
}

sb.append(dp[3][n]).append('\n');
}

System.out.println(sb);

}

}
95 changes: 95 additions & 0 deletions EomSoHyun/BOJ/boj16197.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;

public class Main {

static int n, m;
static char[][] map;
static Queue<int[]> q;

public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());

n = Integer.parseInt(st.nextToken());
m = Integer.parseInt(st.nextToken());
map = new char[n][m];
q = new LinkedList<int[]>();
int[] coin = new int[5];

int idx = 0;
for (int i = 0; i < n; i++) {
String line = br.readLine();
for (int j = 0; j < line.length(); j++) {
map[i][j] = line.charAt(j);
if (map[i][j] == 'o') {
coin[idx++] = i;
coin[idx++] = j;
}
}
}
coin[4] = 0;
q.offer(coin);
System.out.println(bfs());



}

public static int bfs() {
int[] dx = {0, 0, 1, -1};
int[] dy = {1, -1, 0, 0};


while (true) {
int[] xy = q.poll();
int cnt = xy[4];
int[] coin1 = new int[] {xy[0], xy[1]};
int[] coin2 = new int[] {xy[2], xy[3]};

if (cnt++ == 10) break;

for (int i = 0; i < 4; i++) {
int x1 = coin1[0] + dx[i];
int x2 = coin2[0] + dx[i];
int y1 = coin1[1] + dy[i];
int y2 = coin2[1] + dy[i];

if (!(0 <= x1 && x1 < n && 0 <= y1 && y1 < m)) {
if (!(0 <= x2 && x2 < n && 0 <= y2 && y2 < m)) {
// 둘 다 떨어짐
continue;
}
else {
// coin1 떨어짐
return cnt;
}
}
else if (!(0 <= x2 && x2 < n && 0 <= y2 && y2 < m)) {
// coin2 떨어짐
return cnt;
}
else {
if (map[x1][y1] == '#') {
x1 = coin1[0];
y1 = coin1[1];
}
if (map[x2][y2] == '#') {
x2 = coin2[0];
y2 = coin2[1];
}
q.offer(new int[] {x1, y1, x2, y2, cnt});
}

}
}

return -1;

}

}
87 changes: 87 additions & 0 deletions EomSoHyun/BOJ/boj16234.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;

public class Main {

static int N, L, R, sum, cnt;
static int[][] A;
static boolean[][] visited;
static Queue<int[]> pos;
static int[] dx = {0, 0, 1, -1};
static int[] dy = {1, -1, 0, 0};

public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());

N = Integer.parseInt(st.nextToken()); // 땅 크기
L = Integer.parseInt(st.nextToken()); // L명 이상
R = Integer.parseInt(st.nextToken()); // R명 이하

A = new int[N][N]; // 각 나라 인구 수

for (int i = 0; i < N; i++) {
st = new StringTokenizer(br.readLine());
for (int j = 0; j < N; j++) {
A[i][j] = Integer.parseInt(st.nextToken());
}
}


int rst = 0;
pos = new LinkedList<int[]>();
while (true) {
boolean flag = true;
visited = new boolean[N][N]; // 방문 표시
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (!visited[i][j]) {
sum = 0;
cnt = 0;
dfs(i, j);
if (cnt > 1) {
flag = false;
while (!pos.isEmpty()) {
int[] xy = pos.poll();
A[xy[0]][xy[1]] = sum / cnt;
}
} else {
visited[i][j] = false;
pos.clear();
}
}
}
}

if (flag) break;
rst++;
}

System.out.println(rst);

}

public static void dfs(int x, int y) {
pos.offer(new int[] {x, y});
visited[x][y] = true;
sum += A[x][y];
cnt++;

for (int i = 0; i < 4; i++) {
int nx = x + dx[i];
int ny = y + dy[i];
if (0 <= nx && nx < N && 0 <= ny && ny < N) {
if (L <= Math.abs(A[x][y] - A[nx][ny]) && Math.abs(A[x][y] - A[nx][ny]) <= R && !visited[nx][ny]) {
dfs(nx, ny);
}
}

}
}

}
52 changes: 52 additions & 0 deletions EomSoHyun/BOJ/boj16719.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import java.io.*;
import java.util.*;

public class Main {

static String str;
static boolean[] mark;
static StringBuilder sb;

public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
sb = new StringBuilder();

str = br.readLine();
mark = new boolean[str.length()];

ZOAC(0, str.length()-1);

System.out.println(sb);


}

public static void ZOAC(int start, int end) {
if (start > end) {
return;
}

int idx = start;
for (int i = start+1; i <= end; i++) {
if (str.charAt(idx) > str.charAt(i)) {
idx = i;
}
}
mark[idx] = true;
print();
ZOAC(idx+1, end);
ZOAC(start, idx-1);


}

public static void print() {
for (int i = 0; i < str.length(); i++) {
if (mark[i]) {
sb.append(str.charAt(i));
}
}
sb.append('\n');
}

}
77 changes: 77 additions & 0 deletions EomSoHyun/BOJ/boj17297.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

static int m;
static List<Integer> nums;
static String str = "Messi Gimossi";

public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

m = Integer.parseInt(br.readLine());

nums = new ArrayList<>();
nums.add(0);
nums.add(5);
nums.add(13);

int i = 0;
if (m > 13) {
i = 3;
while (true) {
nums.add(nums.get(i - 1) + nums.get(i - 2) + 1);
if (nums.get(i) >= m) break;
i++;
}

}

if (m <= 5) {
i = 1;
}
else if (m <= 13) {
i = 2;
}

Messi(m, i);

}

public static void Messi(int m, int i) {
if (i == 1) {
System.out.println(str.charAt(m-1));
return;
}

else if (i == 2) {
char ch = str.charAt(m-1);
if (ch == ' ') {
System.out.println("Messi Messi Gimossi");
}
else {
System.out.println(ch);
}
return;
}

if (m == nums.get(i-1) + 1) {
System.out.println("Messi Messi Gimossi");
return;
}

if (m > nums.get(i-1)) {
m = m - (nums.get(i-1) + 1);
Messi(m, i-2);
}

else {
Messi(m, i-1);
}
}

}
Loading
Loading