Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
2f8060e
first commit
soyeon37 Jan 30, 2023
994e55b
first commit
soyeon37 Jan 30, 2023
d91caa3
Delete .project
soyeon37 Jan 30, 2023
3a76a15
Delete .classpath
soyeon37 Jan 30, 2023
3c9f71d
Delete bin directory
soyeon37 Jan 30, 2023
cc20049
Delete .settings directory
soyeon37 Jan 30, 2023
928dd3d
Rename src/순열_조합_집합/BOJ_1269.java to 순열_조합_집합/BOJ_1269.java
soyeon37 Jan 30, 2023
a4f22b8
Rename src/순열_조합_집합/BOJ_10972.java to 순열_조합_집합/BOJ_10972.java
soyeon37 Jan 30, 2023
e7f10e5
Rename src/순열_조합_집합/BOJ_11051.java to 순열_조합_집합/BOJ_11051.java
soyeon37 Jan 30, 2023
b3e2556
Rename src/순열_조합_집합/BOJ_9375.java to 순열_조합_집합/BOJ_9375.java
soyeon37 Jan 30, 2023
1b15d67
Rename src/완전탐색/BOJ_1120.java to 완전탐색/BOJ_1120.java
soyeon37 Jan 30, 2023
7b291a9
Rename src/완전탐색/BOJ_18111.java to 완전탐색/BOJ_18111.java
soyeon37 Jan 30, 2023
1863b0c
Rename src/완전탐색/BOJ_2503.java to 완전탐색/BOJ_2503.java
soyeon37 Jan 30, 2023
862d05a
Rename src/완전탐색/BOJ_2615.java to 완전탐색/BOJ_2615.java
soyeon37 Jan 30, 2023
b8a07b0
2월 1주차
soyeon37 Feb 6, 2023
a5df2e6
2월 1주차
soyeon37 Feb 6, 2023
7c2e2ac
Merge branch 'soyeon' of https://github.com/SSAFY9Algorithm/soyeon in…
soyeon37 Feb 6, 2023
004e4e0
2월2주차
soyeon37 Feb 13, 2023
305665c
Add files via upload
soyeon37 Feb 14, 2023
284d477
2월3주차
soyeon37 Feb 18, 2023
6188833
추가
soyeon37 Feb 20, 2023
e9891d6
추가
soyeon37 Feb 20, 2023
13b1820
2월5주차
soyeon37 Feb 27, 2023
ba3c0ad
3월2주차
soyeon37 Mar 13, 2023
764dbb8
3월2주차
soyeon37 Mar 14, 2023
941d0a2
3월 5주차
soyeon37 Mar 27, 2023
9a3a8cf
3월 5주차
soyeon37 Mar 28, 2023
f55c2c9
4월 1주차
soyeon37 Apr 3, 2023
84e4908
4월 3주차
soyeon37 Apr 17, 2023
80409fb
4월 4주차
soyeon37 Apr 25, 2023
fc3581a
4월 4주차
soyeon37 Apr 25, 2023
d5fc7b2
5월 2주차
soyeon37 May 8, 2023
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
171 changes: 171 additions & 0 deletions A형/Main_백준_16236_아기상어_골드3_함소연_140ms.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
package A형;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.StringTokenizer;

public class Main_백준_16236_아기상어_골드3_함소연_140ms {
static class Pos {
int x;
int y;
int dist;

public Pos(int x, int y, int dist) {
this.x = x;
this.y = y;
this.dist = dist;
}
}

private static int minX;
private static int minY;
private static int[][] map;
private static int[] dx = { -1, 0, 1, 0 };
private static int[] dy = { 0, -1, 0, 1 };
private static int time = 0;
private static int shark = 2;
private static int N;
private static int x, y;
private static int minDist;
private static int[][] dist;
private static int cnt;

public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
N = Integer.parseInt(br.readLine());

StringTokenizer st;
dist = new int[N][N];
map = new int[N][N];
for (int i = 0; i < N; i++) {
st = new StringTokenizer(br.readLine());
for (int j = 0; j < N; j++) {
map[i][j] = Integer.parseInt(st.nextToken());
if (map[i][j] == 9) {
x = i;
y = j;
map[i][j] = 0;
}
}
}
go();
System.out.println(time);
}

public static void go() {
while (true) {
init(); // 초기화
// if (!checkCatch())
// return;
bfs();
// 먹을 수 있는 물고기를 찾은 경우
if (minX != Integer.MAX_VALUE && minY != Integer.MAX_VALUE) {
time += dist[minX][minY];
cnt++;
// 먹은 수와 상어의 크기가 같으면 상어크기 증가 후 물고기 수 초기화
if (cnt == shark) {
shark++;
cnt = 0;
}
map[minX][minY] = 0; // 먹은 물고기 위치를 0으로

// 상어 위치 갱신
x = minX;
y = minY;
} else // 먹을 수 있는 물고기가 없는 경우
return;
}
}

// 잡을 수 있는 물고기가 있는 지 확인
public static boolean checkCatch() {
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (map[i][j] != 0 && map[i][j] != 9 && map[i][j] < shark)
return true;
}
}
return false;
}

// 지나갈 수 있는 지 확인
public static boolean checkMove(int nx, int ny) {
if (nx < 0 || nx >= N || ny < 0 || ny >= N)
return false; // 범위 체크
if (map[nx][ny] > shark)
return false; // 크기 체크
return true;
}

// 가장 가까운 물고기 찾기
public static void bfs() {
Deque<Pos> queue = new ArrayDeque<Pos>();
queue.offer(new Pos(x, y, 0));
dist[x][y] = 0;

while (queue.size() > 0) {
Pos p = queue.poll();
for (int i = 0; i < 4; i++) {
int nx = p.x + dx[i];
int ny = p.y + dy[i];
// 범위 체크
if (!checkMove(nx, ny))
continue;
// 이미 방문했거나, 상어 크기보다 큰 물고기 건너 뛰기
if (dist[nx][ny] != -1 || map[nx][ny] > shark)
continue;
// nx, ny에 있는 물고기까지의 이동거리 갱신
dist[nx][ny] = dist[p.x][p.y] + 1;
// 먹을 수 있는 물고기일 경우
if(map[nx][ny] != 0 && map[nx][ny] < shark) {
// 현재 물고기까지의 이동시간이 더 짧은 경우
if (minDist > dist[nx][ny]) {
minX = nx;
minY = ny;
minDist = dist[nx][ny];
// 현재 물고기까지의 이동시간이 같으면 가장 위쪽, 가장 왼쪽 찾기
} else if (minDist == dist[nx][ny]) {
// 가장 위쪽에 있다면 가장 왼쪽인지 확인
if (minX == nx) {
if (minY > ny) {
minX = nx;
minY = ny;
}
// 가장 위쪽인지 확인
} else if (minX > nx) {
minX = nx;
minY = ny;
}
}
}
queue.offer(new Pos(nx, ny, dist[nx][ny]));
}
}
}

public static void init() {
minDist = Integer.MAX_VALUE;
minX = Integer.MAX_VALUE;
minY = Integer.MAX_VALUE;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
dist[i][j] = -1;
}
}
}

// public static void print() {
// for (int i = 0; i < N; i++) {
// for (int j = 0; j < N; j++) {
// if (i == x && j == y)
// System.out.print("■" + " ");
// else
// System.out.print(map[i][j] + " ");
// }
// System.out.println();
// }
// }
}
109 changes: 109 additions & 0 deletions A형/Main_백준_16637_괄호추가하기_골드3_함소연_80ms.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package A형;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main_백준_16637_괄호추가하기_골드3_함소연_80ms {
private static int N;
private static char[] op;
private static int[] num;
private static int MAX = Integer.MIN_VALUE;
private static boolean[] isSelected;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

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

String str = br.readLine();
op = new char[N / 2];
num = new int[N / 2 + 1];
int nIdx = 0, oIdx = 0;
for (int i = 0; i < N; i++) {
if(i % 2 == 0) {
num[nIdx++] = str.charAt(i) - '0';
}else {
op[oIdx++] = str.charAt(i);
}
}
isSelected = new boolean[N / 2];
go(0);
System.out.println(MAX);
}

private static void go(int idx) {
if(idx == N/2) {
for (int i = 0; i < isSelected.length - 1; i++) {
if(isSelected[i] && isSelected[i+1]) {
return;
}
}
Cal();
return;
}

isSelected[idx] = true;
go(idx + 1);
isSelected[idx] = false;
go(idx + 1);
}

private static void Cal() {
// 괄호 계산
int total = 0;
int[] temp = Arrays.copyOf(num, num.length);
for (int i = 0; i < isSelected.length; i++) {
if(!isSelected[i]) continue;
switch (op[i]) {
case '-':
temp[i] = num[i] - num[i+1];
temp[i+1] = 100; // pass
total++;
break;
case '+':
temp[i] = num[i] + num[i+1];
temp[i+1] = 100; // pass
total++;
break;
case '*':
temp[i] = num[i] * num[i+1];
temp[i+1] = 100; // pass
total++;
break;
default:
break;
}
}
// 최종 계산
int idx = 0;
int[] newNum = new int[N / 2 + 1 - total];
for (int i = 0; i < temp.length; i++) {
if(temp[i] == 100) continue;
newNum[idx++] = temp[i];
}
idx = 0;
char[] newOp = new char[N / 2 - total];
for (int i = 0; i < op.length; i++) {
if(isSelected[i]) continue;
newOp[idx++] = op[i];
}
int res = newNum[0];
for (int i = 0; i < newOp.length; i++) {
switch (newOp[i]) {
case '-':
res -= newNum[i+1];
break;
case '+':
res += newNum[i+1];
break;
case '*':
res *= newNum[i+1];
break;
default:
break;
}
}
MAX = Math.max(MAX, res);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package A형;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main_백준_17070_파이프옮기기1_골드5_함소연_252ms {
static int[] position = { 0, 1, 2 }; // 0 : 가로, 1 : 세로, 2 : 대각선
private static int N;
private static int total;
private static int[][] map;

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

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

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

move(0, 1, 0);
System.out.println(total);
}

private static void move(int x, int y, int pos) {
if (x == N - 1 && y == N - 1) {
total++;
return;
}
switch (pos) {
case 0:
// 가로
horizontal(x, y);
// 대각선
diagonal(x, y);
break;
case 1:
// 세로
vertical(x, y);
// 대각선
diagonal(x, y);
break;
case 2:
// 가로
horizontal(x, y);
// 세로
vertical(x, y);
// 대각선
diagonal(x, y);
break;
default:
break;
}
}

// 범위 체크
public static boolean checkMove(int x, int y, int pos) {
if (x < 0 || x >= N || y < 1 || y >= N || map[x][y] == 1) return false;
// 대각선 체크
if(pos == 2) {
if(map[x][y-1] == 1 || map[x-1][y] == 1) return false;
}
return true;
}
// 가로
public static void horizontal(int x, int y) {
int nx = x;
int ny = y + 1;
if (checkMove(nx, ny, 0)) {
move(nx, ny, 0);
}
}
// 세로
public static void vertical(int x, int y) {
int nx = x + 1;
int ny = y;
if (checkMove(nx, ny, 1)) {
move(nx, ny, 1);
}
}
// 대각선
public static void diagonal(int x, int y) {
int nx = x + 1;
int ny = y + 1;
if (checkMove(nx, ny, 2)) {
move(nx, ny, 2);
}
}

}
Loading