├── .github └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── AllyHyeseongKim └── 1952inSWExpertAcademy.c ├── Changhwan ├── baekjoon1018.cpp └── baekjoon6593_sangbum_building.cpp ├── HwangMinji ├── swea1952.cpp ├── 괄호-황민지.cpp └── 퇴사.cpp ├── Hyochang ├── building.cpp ├── chess.c ├── chess_idea.txt └── first.txt ├── Jin ├── 1018_체스판다시칠하기.java ├── 14501_퇴사.java ├── 15685_드래곤커브.java ├── 17135_캐슬 디펜스.java ├── 2583_영역구하기.java ├── 2869_달팽이는 올라가고 싶다.java ├── 6593_상범빌딩.java ├── 7562_나이트의이동.java ├── 9012_괄호.java ├── sw_1952_수영장.java └── 색종이.java ├── JuRyun ├── 14501_퇴사.java ├── 15685_드래곤커브.java ├── 2583_영역구하기.java └── 7562_나이트의이동.java ├── KIMSUNGJAE └── 2583.java ├── LimGeon ├── 6593_LimGeon.cpp └── LimGeon_1018.cpp ├── MINWOOK ├── 15683-윤민욱.java └── 2583-윤민욱.java ├── PJH ├── 1018_체스판다시칠하기.java ├── 14501_퇴사.java ├── 15685_드래곤커브.java ├── 2583_영역구하기.java └── 6593_상범빌딩.java ├── README.md ├── Taehong ├── 14502-LabProblem.java └── 15684-LadderOperation.java ├── Yonglee └── 15685-DragonCurve.java ├── git_tturami.png ├── hyunsik └── 17135.cpp ├── junhuikim ├── 1952-수영장.cpp ├── 7562-나이트의이동.cpp └── README.md ├── minji └── 2583-영역구하기.cpp ├── mose ├── 1952-수영장.cpp ├── Solution_nogada.cpp ├── 아기상어_제출용.cpp ├── 원판돌리기_시작.cpp └── 주사위 윷놀이.cpp ├── sangil ├── 20190303 │ └── Intro.md ├── Git-tturmi.md └── Readme.md └── seungjin ├── input.txt ├── redrawChessMap.py └── redrawChessMapVer2.py /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 1. Algorithm 2 | 3 | 4 | 5 | 2. Time Complexity 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # IntelliJ 2 | .Idea 3 | 4 | # MacOS 5 | .DS_Store/ 6 | 7 | # Output 8 | .out 9 | -------------------------------------------------------------------------------- /AllyHyeseongKim/1952inSWExpertAcademy.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/git-tturami/algorithm/aa61bdfa3d41f33dcf70c79ceb3c139a46fb6008/AllyHyeseongKim/1952inSWExpertAcademy.c -------------------------------------------------------------------------------- /Changhwan/baekjoon1018.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int cal(int s_w, int s_h); 5 | 6 | int w, h; 7 | char before = 'S'; 8 | int best = 64; 9 | int temp = 0; 10 | char board[50][50]; 11 | 12 | int main() { 13 | 14 | cin >> h; 15 | cin >> w; 16 | 17 | for (int i = 0; i < h; i++) { 18 | cin >> board[i]; 19 | } 20 | 21 | for (int i = 0; i < h - 7; i++) { 22 | for (int j = 0; j < w - 7; j++) { 23 | cal(i, j); 24 | } 25 | } 26 | 27 | cout << best << endl; 28 | return 0; 29 | } 30 | 31 | 32 | int cal(int s_h, int s_w) { 33 | 34 | before = 'S'; 35 | temp = 0; 36 | for (int i = s_h; i < s_h + 8; i++) { 37 | 38 | if (before == 'W') before = 'B'; 39 | else if (before == 'B') before = 'W'; 40 | else before = 'S'; 41 | 42 | for (int j = s_w; j < s_w + 8; j++) { 43 | if (before == 'W') { 44 | if (board[i][j] == 'W') { 45 | temp++; 46 | /*if (temp >= best) { 47 | return 0; 48 | }*/ 49 | } 50 | before = 'B'; 51 | } 52 | else if (before == 'B') { 53 | if (board[i][j] == 'B') { 54 | temp++; 55 | /*if (temp >= best) { 56 | return 0; 57 | }*/ 58 | } 59 | before = 'W'; 60 | } 61 | else before = board[i][j]; 62 | } 63 | } 64 | if (best > temp) best = temp; 65 | 66 | before = 'S'; 67 | temp = 0; 68 | 69 | for (int i = s_h; i < s_h + 8; i++) { 70 | 71 | if (before == 'W') before = 'B'; 72 | else if (before == 'B') before = 'W'; 73 | else before = 'S'; 74 | 75 | for (int j = s_w; j < s_w + 8; j++) { 76 | if (before == 'W') { 77 | if (board[i][j] == 'W') { 78 | temp++; 79 | /*if (temp >= best) { 80 | return 0; 81 | }*/ 82 | } 83 | before = 'B'; 84 | } 85 | else if (before == 'B') { 86 | if (board[i][j] == 'B') { 87 | temp++; 88 | /*if (temp >= best) { 89 | return 0; 90 | }*/ 91 | } 92 | before = 'W'; 93 | } 94 | else { 95 | temp++; 96 | if (board[i][j] == 'W') { 97 | before = 'B'; 98 | } 99 | else before = 'W'; 100 | } 101 | } 102 | } 103 | if (best > temp) best = temp; 104 | 105 | return 0; 106 | } -------------------------------------------------------------------------------- /Changhwan/baekjoon6593_sangbum_building.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | char building[30][30][30]; 6 | char building_t[30][30][30]; 7 | int l, r, c; 8 | int s_l, s_r, s_c; 9 | int d_l, d_r, d_c; 10 | int t_lrc[3]; 11 | int best; 12 | int temp; 13 | char s[10]; 14 | 15 | struct point{ 16 | int n_l; 17 | int n_r; 18 | int n_c; 19 | 20 | int move; 21 | }; 22 | 23 | point point_t; 24 | 25 | queue q; 26 | 27 | int main() { 28 | while (1) { 29 | best = 9999; 30 | temp = 0; 31 | cin >> l; 32 | cin >> r; 33 | cin >> c; 34 | 35 | if (l == 0 && r == 0 && c == 0) break; 36 | 37 | for (int i = 0; i < l; i++) { 38 | for (int j = 0; j < r; j++) { 39 | cin >> building[i][j]; 40 | } 41 | cin.getline(s, 5); 42 | } 43 | 44 | for (int i = 0; i < l; i++) { 45 | for (int j = 0; j < r; j++) { 46 | for (int k = 0; k < c; k++) { 47 | if (building[i][j][k] == '.') building_t[i][j][k] = '1'; 48 | else if (building[i][j][k] == 'S') { 49 | q.push({ i,j,k,0 }); 50 | building_t[i][j][k] = '0'; 51 | } else if (building[i][j][k] == 'E') { 52 | building_t[i][j][k] = '2'; 53 | } else building_t[i][j][k] = '0'; 54 | } 55 | } 56 | } 57 | 58 | while (1) { 59 | if (best != 9999) break; 60 | if (q.empty()) { 61 | cout << "Trapped!" << endl; 62 | break; 63 | } 64 | point_t = q.front(); 65 | q.pop(); 66 | t_lrc[0] = point_t.n_l; 67 | t_lrc[1] = point_t.n_r; 68 | t_lrc[2] = point_t.n_c; 69 | temp = ++point_t.move; 70 | for (int i = 0; i < 3; i++) { 71 | t_lrc[i]++; 72 | if (t_lrc[0] < l && t_lrc[1] < r && t_lrc[2] < c) { 73 | if (building_t[t_lrc[0]][t_lrc[1]][t_lrc[2]] == '1') { 74 | q.push({ t_lrc[0], t_lrc[1], t_lrc[2], temp }); 75 | building_t[t_lrc[0]][t_lrc[1]][t_lrc[2]] = '0'; 76 | } 77 | if (building_t[t_lrc[0]][t_lrc[1]][t_lrc[2]] == '2') { 78 | best = temp; 79 | 80 | cout << "Escaped in " << best <<" minute(s)." << endl; 81 | break; 82 | } 83 | } 84 | t_lrc[i] -= 2; 85 | if (t_lrc[0] >= 0 && t_lrc[1] >= 0 && t_lrc[2] >= 0) { 86 | if (building_t[t_lrc[0]][t_lrc[1]][t_lrc[2]] == '1') { 87 | q.push({ t_lrc[0], t_lrc[1], t_lrc[2], temp }); 88 | building_t[t_lrc[0]][t_lrc[1]][t_lrc[2]] = '0'; 89 | } 90 | if (building_t[t_lrc[0]][t_lrc[1]][t_lrc[2]] == '2') { 91 | best = temp; 92 | 93 | cout << "Escaped in " << best << " minute(s)." << endl; 94 | break; 95 | } 96 | } 97 | t_lrc[i]++; 98 | } 99 | } 100 | while (!q.empty()) { 101 | q.pop(); 102 | } 103 | 104 | } 105 | 106 | 107 | 108 | 109 | return 0; 110 | } 111 | 112 | 113 | -------------------------------------------------------------------------------- /HwangMinji/swea1952.cpp: -------------------------------------------------------------------------------- 1 | /* SWEA-1952 */ 2 | 3 | #include 4 | using namespace std; 5 | 6 | #define N 12 7 | 8 | int MAX, day, month, thMonth; 9 | int schedule[N + 1]; 10 | int d[N + 1]; 11 | 12 | void dfs(int cnt, int sum) { 13 | if (sum > MAX) return; 14 | if (cnt > 12) { 15 | MAX = sum < MAX ? sum : MAX; 16 | return; 17 | } 18 | 19 | dfs(cnt + 1, sum + d[cnt]); 20 | dfs(cnt + 3, sum + thMonth); 21 | } 22 | 23 | int main() { 24 | int tc; 25 | scanf("%d", &tc); 26 | 27 | for (int T = 1; T <= tc; T++) { 28 | scanf("%d %d %d %d", &day, &month, &thMonth, &MAX); 29 | 30 | for (int i = 1; i <= N; i++) { 31 | scanf("%d", &schedule[i]); 32 | d[i] = schedule[i] * day < month ? schedule[i] * day : month; 33 | } 34 | 35 | dfs(1, 0); 36 | printf("#%d %d\n", T, MAX); 37 | } 38 | 39 | return 0; 40 | } -------------------------------------------------------------------------------- /HwangMinji/괄호-황민지.cpp: -------------------------------------------------------------------------------- 1 | #pragma warning (disable:4996) 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | #define N 52 7 | 8 | struct stack { 9 | char arr[N] = { 0, }; 10 | int ptr = -1; 11 | 12 | char top() { 13 | return arr[ptr]; 14 | } 15 | 16 | void push(char c) { 17 | ptr++; 18 | arr[ptr] = c; 19 | } 20 | 21 | void pop() { 22 | if (ptr == -1) printf("Stack is empty.\n"); 23 | else { 24 | arr[ptr] = 0; 25 | ptr--; 26 | } 27 | } 28 | 29 | int stkSize() { 30 | return ptr + 1; 31 | } 32 | }; 33 | 34 | int main() { 35 | freopen("input.txt.", "r", stdin); 36 | int tc; 37 | scanf("%d", &tc); 38 | 39 | for (int T = 1; T <= tc; T++) { 40 | char str[N] = { 0, }; 41 | scanf("%s", str); 42 | 43 | stack stk; 44 | 45 | for (int i = 0; i < strlen(str); i++) { 46 | if (str[i] == '(') { 47 | stk.push(str[i]); 48 | } 49 | else if (str[i] == ')') { 50 | if (stk.top() == '(') { 51 | stk.pop(); 52 | } 53 | else { 54 | stk.push(str[i]); 55 | break; 56 | } 57 | } 58 | } 59 | 60 | if (stk.stkSize() == 0) printf("YES\n"); 61 | else printf("NO\n"); 62 | } 63 | return 0; 64 | } -------------------------------------------------------------------------------- /HwangMinji/퇴사.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/git-tturami/algorithm/aa61bdfa3d41f33dcf70c79ceb3c139a46fb6008/HwangMinji/퇴사.cpp -------------------------------------------------------------------------------- /Hyochang/building.cpp: -------------------------------------------------------------------------------- 1 | #define _CRT_SECURE_NO_WARNINGS 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | struct position { 8 | 9 | int z, y, x; 10 | int cnt; 11 | 12 | }typedef p; 13 | 14 | queue

q; 15 | 16 | char visited[30][30][31]; 17 | 18 | int main() 19 | { 20 | int l, r, c; 21 | char map[30][30][31]; 22 | int dx[] = { 1,-1,0,0,0,0 }; 23 | int dy[] = { 0,0,1,-1,0,0 }; 24 | int dz[] = { 0,0,0,0,1,-1 }; 25 | 26 | while (1) { 27 | scanf("%d %d %d", &l, &r, &c); 28 | if (l == 0 && r == 0 && c == 0) break; 29 | for (int i = 0; i < l; i++) { 30 | for (int j = 0; j < r; j++) { 31 | scanf("%s", map[i][j]); 32 | 33 | } 34 | } 35 | 36 | int flag = 0; 37 | for (int i = 0; i < l; i++) { 38 | for (int j = 0; j < r; j++) { 39 | for (int k = 0; k < c; k++) { 40 | if (map[i][j][k] == 'S') { 41 | p start = { i,j,k,0 }; 42 | q.push(start); 43 | while (!q.empty() && flag == 0) { 44 | p now = q.front(); 45 | q.pop(); 46 | for (int m = 0; m < 6; m++) { 47 | p next = { now.z + dz[m],now.y + dy[m],now.x + dx[m],now.cnt + 1 }; 48 | if (0 <= next.z && next.z < l && 0 <= next.y && next.y < r && 0 <= next.x && next.x < c) { 49 | if (visited[next.z][next.y][next.x] == 0 && map[next.z][next.y][next.x] != '#') { 50 | visited[next.z][next.y][next.x] = 1; 51 | if (map[next.z][next.y][next.x] == 'E') { 52 | printf("Escaped in %d minute(s).\n", next.cnt); 53 | flag = 1; 54 | } 55 | q.push(next); 56 | } 57 | } 58 | } 59 | } 60 | } 61 | } 62 | } 63 | } 64 | while (!q.empty()) q.pop(); 65 | for (int i = 0; i < l; i++) { 66 | for (int j = 0; j < r; j++) { 67 | for (int k = 0; k < c; k++) 68 | visited[i][j][k] = 0; 69 | } 70 | } 71 | if (flag == 0) printf("Trapped!\n"); 72 | } 73 | return 0; 74 | } -------------------------------------------------------------------------------- /Hyochang/chess.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/git-tturami/algorithm/aa61bdfa3d41f33dcf70c79ceb3c139a46fb6008/Hyochang/chess.c -------------------------------------------------------------------------------- /Hyochang/chess_idea.txt: -------------------------------------------------------------------------------- 1 | 자를 수 있는 모든 경우의 체스판을 1개씩 저장해서, 2 | 1개씩 바꿔야하는 정사각형의 개수를 세고, 3 | 그 체스판 마다의 값 중에서 최솟값을 가진 보드를 선택하고, 최솟값을 출력한다. 4 | 5 | 체스판의 바꿔야 할 정사각형의 개수를 셀 때는, 6 | 7 | 2가지 경우를 나눠 생각한다. 8 | 9 | 1. 첫 째판이 검정일 때 10 | 11 | 모든 홀수 판의 합을 구해 모든 홀수 판이 검정일 값과의 차이를 구하고 12 | 13 | 짝수 판은 반대로 흰색을 고려한다. 14 | 15 | 2. 첫 째판이 흰색일 때 16 | 17 | 첫 번째 경우와 반대로 생각하면 된다. -------------------------------------------------------------------------------- /Hyochang/first.txt: -------------------------------------------------------------------------------- 1 | Hi -------------------------------------------------------------------------------- /Jin/1018_체스판다시칠하기.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Main { 4 | static int M; 5 | static int N; 6 | static char[][] map; 7 | static char[][] tmp; 8 | 9 | public static void main(String[] args) { 10 | // TODO Auto-generated method stub 11 | Scanner sc = new Scanner(System.in); 12 | int M = sc.nextInt(); 13 | int N = sc.nextInt(); 14 | 15 | map = new char[M][N]; 16 | tmp = new char[8][8]; 17 | 18 | int min = 99999; 19 | 20 | for(int i=0;i= count) { 51 | min = count; 52 | } 53 | } 54 | } 55 | System.out.println(min); 56 | } 57 | 58 | public static int checkLeft(int m, int n, int change) { 59 | for(int i=0;i<8;i++) { 60 | for(int j=0;j<8;j++) { 61 | if(i>0 && tmp[i][j] == tmp[i-1][j]) { 62 | if(tmp[i-1][j] == 'W') { 63 | tmp[i][j] = 'B'; 64 | } 65 | else{ 66 | tmp[i][j] = 'W'; 67 | } 68 | change++; 69 | } 70 | else if(j>0 && tmp[i][j] == tmp[i][j-1]) { 71 | if(tmp[i][j-1] == 'W') { 72 | tmp[i][j] = 'B'; 73 | } 74 | else{ 75 | tmp[i][j] = 'W'; 76 | } 77 | change++; 78 | } 79 | } 80 | } 81 | return change; 82 | } 83 | 84 | 85 | public static void set(int m, int n) { 86 | for(int i=0;i<8;i++) { 87 | for(int j=0;j<8;j++) { 88 | tmp[i][j] = map[i+m][j+n]; 89 | } 90 | } 91 | } 92 | } -------------------------------------------------------------------------------- /Jin/14501_퇴사.java: -------------------------------------------------------------------------------- 1 | package hii; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Main { 6 | 7 | static class work { 8 | int t; 9 | int p; 10 | } 11 | 12 | static int N; 13 | static work[] Work; 14 | static int max; 15 | 16 | public static void main(String[] args) { 17 | // TODO Auto-generated method stub 18 | Scanner scan = new Scanner(System.in); 19 | N = scan.nextInt(); 20 | int t, p; 21 | Work = new work[N]; 22 | 23 | for (int i = 0; i < N; i++) { 24 | t = scan.nextInt(); 25 | p = scan.nextInt(); 26 | Work[i] = new work(); 27 | Work[i].t = t; 28 | Work[i].p = p; 29 | } 30 | 31 | max = 0; 32 | 33 | for(int i = 0;i max){ 55 | max = money; 56 | } 57 | } 58 | 59 | 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Jin/15685_드래곤커브.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Main { 4 | 5 | static int[][] point; 6 | static Dragon[] dragon; 7 | static int N; 8 | static int number; 9 | 10 | static class Dragon { 11 | int x; 12 | int y; 13 | int d; 14 | int g; 15 | } 16 | 17 | public static void main(String[] args) { 18 | Scanner scan = new Scanner(System.in); 19 | point = new int[101][101]; 20 | for (int i = 0; i < 101; i++) { 21 | for (int j = 0; j < 101; j++) { 22 | point[i][j] = 0; 23 | } 24 | } 25 | 26 | N = scan.nextInt(); 27 | dragon = new Dragon[N]; 28 | 29 | for (int i = 0; i < N; i++) { 30 | dragon[i] = new Dragon(); 31 | dragon[i].x = scan.nextInt(); 32 | dragon[i].y = scan.nextInt(); 33 | dragon[i].d = scan.nextInt(); 34 | dragon[i].g = scan.nextInt(); 35 | } 36 | 37 | for (int i = 0; i < N; i++) { 38 | point[dragon[i].x][dragon[i].y] = 1; 39 | numDragons(i); 40 | } 41 | 42 | int resultnum = numResult(); 43 | 44 | System.out.println(resultnum); 45 | } 46 | 47 | static void numDragons(int i) { 48 | int start = 0; 49 | int end = 0; 50 | int x = dragon[i].x; 51 | int y = dragon[i].y; 52 | 53 | int[] result = new int[(int) Math.pow(2, dragon[i].g)]; 54 | for (int j = 0; j < result.length; j++) { 55 | result[j] = -1; 56 | } 57 | 58 | result[0] = dragon[i].d; 59 | 60 | for (int j = 0; j < dragon[i].g; j++) { 61 | int[] tmp = new int[(int) Math.pow(2, j + 1)]; 62 | 63 | for (int k = 0; k < tmp.length; k++) { 64 | tmp[k] = result[k]; 65 | } 66 | x = dragon[i].x; 67 | y = dragon[i].y; 68 | 69 | start = 0; 70 | end = tmp.length - 1; 71 | 72 | while (tmp[start] != -1) { 73 | switch (tmp[start]) { 74 | case 0: 75 | x += 1; 76 | result[end - start] = 1; 77 | start++; 78 | break; 79 | 80 | case 1: 81 | y -= 1; 82 | result[end - start] = 2; 83 | start++; 84 | break; 85 | 86 | case 2: 87 | x -= 1; 88 | result[end - start] = 3; 89 | start++; 90 | break; 91 | 92 | case 3: 93 | y += 1; 94 | result[end - start] = 0; 95 | start++; 96 | break; 97 | } 98 | } 99 | } 100 | 101 | x = dragon[i].x; 102 | y = dragon[i].y; 103 | 104 | for(int k=0;k15 || M<3 || M>15 || D<1 || D>10) { 36 | return; 37 | } 38 | 39 | map = new int[N + 1][M]; 40 | max = 0; 41 | 42 | ArrayList pointMap = new ArrayList<>(); 43 | 44 | 45 | for (int i = 0; i < N; i++) { 46 | for (int j = 0; j < M; j++) { 47 | if(in.nextInt() == 1) { 48 | pointMap.add(new point(i, j)); 49 | } 50 | } 51 | } 52 | 53 | for (int i = 0; i < M; i++) { 54 | for (int j = i+1; j < M; j++) { 55 | for (int k = j+1; k < M; k++) { 56 | ArrayList tmpList = new ArrayList<>(); 57 | for(point p:pointMap) { 58 | tmpList.add(new point(p.x,p.y)); 59 | } 60 | dfs(N,M, D, i, j, k,tmpList); 61 | } 62 | } 63 | } 64 | 65 | System.out.println(max); 66 | 67 | } 68 | 69 | public static void dfs(int N, int M, int D, int i, int j, int k, ArrayList tmpList) { 70 | count = 0; 71 | int numss = 0; 72 | 73 | ArrayList index = new ArrayList<>(); 74 | 75 | while (tmpList.size() > 0) { 76 | index.clear(); 77 | tmpList = distance(tmpList, N, D, i, j, k); 78 | if (max < count) { 79 | max = count; 80 | numss = count; 81 | } 82 | 83 | for (point p : tmpList) { 84 | if (p.x < N-1) { 85 | p.x += 1; 86 | } else { 87 | index.add(tmpList.indexOf(p)); 88 | } 89 | } 90 | 91 | if(index.size()>0) { 92 | for(int a = index.size()-1;a>=0;a--) { 93 | int indexing = index.get(a); 94 | tmpList.remove(indexing); 95 | } 96 | } 97 | 98 | } 99 | } 100 | 101 | public static ArrayList distance(ArrayList tmpList, int N, int D, int i, int j, int k) { 102 | int first = -1, second = -1, third = -1; 103 | int firstmin = 100, secondmin = 100, thirdmin = 100; 104 | //ArrayList indexnum = new ArrayList<>(); 105 | 106 | for (point p : tmpList) { 107 | int f = Math.abs(N-p.x) + Math.abs(i-p.y); 108 | int s = Math.abs(N-p.x) + Math.abs(j-p.y); 109 | int t = Math.abs(N-p.x) + Math.abs(k-p.y); 110 | 111 | if (f <= D && f<=firstmin) { 112 | if(f == firstmin) { 113 | if(p.y=0 || second >= 0 || third >= 0) { 165 | if(first == second && first== third) { 166 | tmpList.remove(first); 167 | count++; 168 | } 169 | else if(first == second) { 170 | if(third >= 0) { 171 | tmpList.remove(third); 172 | count++; 173 | } 174 | if(first >=0) { 175 | tmpList.remove(first); 176 | count++; 177 | } 178 | 179 | } 180 | else if(second == third) { 181 | if(second >=0) { 182 | tmpList.remove(second); 183 | count++; 184 | } 185 | if(first >=0) { 186 | tmpList.remove(first); 187 | count++; 188 | } 189 | 190 | } 191 | 192 | else { 193 | if(third >= 0) { 194 | tmpList.remove(third); 195 | count++; 196 | } 197 | if(second >= 0) { 198 | tmpList.remove(second); 199 | count++; 200 | } 201 | if(first >= 0) { 202 | tmpList.remove(first); 203 | count++; 204 | } 205 | 206 | } 207 | 208 | } 209 | 210 | 211 | return tmpList; 212 | } 213 | } 214 | -------------------------------------------------------------------------------- /Jin/2583_영역구하기.java: -------------------------------------------------------------------------------- 1 | import java.lang.reflect.Array; 2 | import java.util.ArrayList; 3 | import java.util.Collections; 4 | import java.util.Scanner; 5 | import java.util.Stack; 6 | 7 | public class Main { 8 | 9 | static int[][] Map; 10 | static int M,N,K; 11 | 12 | static class Sqaurepoint{ 13 | int sx; 14 | int sy; 15 | int ex; 16 | int ey; 17 | } 18 | static Sqaurepoint[] p; 19 | 20 | static class point{ 21 | int x; 22 | int y; 23 | public point(int x, int y){ 24 | this.x = x; 25 | this.y = y; 26 | } 27 | } 28 | static Stack stack; 29 | 30 | static ArrayList areaList; 31 | static int area; 32 | 33 | public static void main(String[] args) { 34 | Scanner scanner = new Scanner(System.in); 35 | N = scanner.nextInt(); 36 | M = scanner.nextInt(); 37 | K = scanner.nextInt(); 38 | 39 | p = new Sqaurepoint[K]; 40 | 41 | for(int i = 0;i(); 66 | areaList = new ArrayList(); 67 | 68 | int num = numbering(); 69 | 70 | System.out.println(num); 71 | for(int i=0;i= 1 && Map[x][y - 1] == -1) stack.push(new point(x, y - 1)); // 아래 82 | if (x >= 1 && Map[x - 1][y] == -1) stack.push(new point(x - 1, y)); // 왼쪽 83 | 84 | if (!stack.empty()) { 85 | point np = stack.pop(); // 스택의 가장 마지막것이 나옴 86 | findSquare(np.x, np.y, count); 87 | } 88 | } 89 | 90 | public static int numbering(){ 91 | int count = 1; 92 | area = 0; 93 | for(int i = 0;i queue; 21 | static int[][][] visit; 22 | static int L; 23 | static int R; 24 | static int C; 25 | 26 | public static void main(String[] args) { 27 | Scanner sc = new Scanner(System.in); 28 | while(true){ 29 | L = sc.nextInt(); 30 | if(L == 0){ 31 | break; 32 | } 33 | R = sc.nextInt(); 34 | C = sc.nextInt(); 35 | 36 | map = new char[L][R][C]; 37 | visit = new int[L][R][C]; 38 | 39 | int startL = 0; 40 | int startR = 0; 41 | int startC = 0; 42 | int endL = 0; 43 | int endR = 0; 44 | int endC = 0; 45 | 46 | for(int i=0;i(); 67 | int count = bfs(startL, startR, startC, 0, endL, endR, endC); 68 | if(count != 0){ 69 | System.out.println("Escaped in "+count+" minute(s)."); 70 | } 71 | else{ 72 | System.out.println("Trapped!"); 73 | } 74 | } 75 | 76 | } 77 | 78 | public static int bfs(int i,int j,int k, int count, int endL, int endR, int endC){ 79 | queue.add(new point(i,j,k,count)); 80 | visit[i][j][k] = 1; 81 | point result = new point(0,0,0,0); 82 | 83 | while(!queue.isEmpty()){ 84 | point p = queue.poll(); 85 | result = p; 86 | if(map[p.tL][p.tR][p.tC] == 'E'){ 87 | break; 88 | } 89 | else{ 90 | i = p.tL; 91 | j = p.tR; 92 | k = p.tC; 93 | 94 | if(i>0 && visit[i-1][j][k] == 0 && (map[i-1][j][k] == '.' || map[i-1][j][k] == 'E')){ // 위 95 | queue.add(new point(i-1, j, k, p.count+1)); 96 | visit[i-1][j][k] = 1; 97 | } 98 | if(i0 && visit[i][j-1][k] == 0 && (map[i][j-1][k] == '.' || map[i][j-1][k] == 'E')){ // 북 103 | queue.add(new point(i, j-1, k, p.count+1)); 104 | visit[i][j-1][k] = 1; 105 | } 106 | if(j0 && visit[i][j][k-1] == 0 && (map[i][j][k-1] == '.' || map[i][j][k-1] == 'E')){ // 서 111 | queue.add(new point(i, j, k-1, p.count+1)); 112 | visit[i][j][k-1] = 1; 113 | } 114 | if(k queue; 28 | 29 | static class Chess { 30 | int l; 31 | int x1, y1; 32 | int x2, y2; 33 | } 34 | 35 | static int[] dx = { 2, 1, -1, -2 }; 36 | static int[] dy = { 2, 1, -1, -2 }; 37 | 38 | public static void main(String[] args) { 39 | // TODO Auto-generated method stub 40 | Scanner scan = new Scanner(System.in); 41 | N = scan.nextInt(); 42 | int[] num = new int[N]; 43 | chess = new Chess[N]; 44 | n_count = 0; 45 | 46 | for (int i = 0; i < N; i++) { 47 | chess[i] = new Chess(); 48 | chess[i].l = scan.nextInt(); 49 | chess[i].x1 = scan.nextInt(); 50 | chess[i].y1 = scan.nextInt(); 51 | chess[i].x2 = scan.nextInt(); 52 | chess[i].y2 = scan.nextInt(); 53 | } 54 | 55 | 56 | for (int i = 0; i < N; i++) { 57 | visit = new int[chess[i].l][chess[i].l]; 58 | queue = new LinkedList<>(); 59 | queue.clear(); 60 | findCount(i); 61 | System.out.println(n_count); 62 | n_count = 0; 63 | } 64 | 65 | } 66 | 67 | public static void findCount(int n) { 68 | if (chess[n].x1 == chess[n].x2 && chess[n].y1 == chess[n].y2) { 69 | n_count = 0; 70 | } 71 | 72 | else { 73 | bfs(chess[n].x1, chess[n].y1,n,0); 74 | } 75 | } 76 | 77 | public static void bfs(int x,int y,int n,int count) { 78 | for (int j = 0; j < 4; j++) { 79 | for (int k = 0; k < 4; k++) { 80 | if (Math.abs(dx[j]) != Math.abs(dy[k])) { 81 | int xx = x + dx[j]; 82 | int yy = y + dy[k]; 83 | 84 | 85 | if(xx < chess[n].l && yy < chess[n].l && xx>=0 && yy>=0) { 86 | if(xx == chess[n].x2 && yy == chess[n].y2) { 87 | n_count = count+1; 88 | queue.clear(); 89 | return; 90 | } 91 | else { 92 | if(visit[xx][yy] != 1) 93 | queue.add(new point(xx, yy,count)); 94 | visit[xx][yy] = 1; 95 | } 96 | } 97 | 98 | } 99 | } 100 | } 101 | 102 | if(!queue.isEmpty()) { 103 | point mpoint = queue.poll(); 104 | bfs(mpoint.x, mpoint.y,n,(mpoint.count)+1); 105 | } 106 | else return; 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /Jin/9012_괄호.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.LinkedList; 3 | import java.util.Queue; 4 | import java.util.Scanner; 5 | import java.util.Stack; 6 | 7 | public class Main { 8 | 9 | 10 | public static void main(String[] args) { 11 | // TODO Auto-generated method stub 12 | Scanner scan = new Scanner(System.in); 13 | Stack stack = new Stack(); 14 | ArrayList arrayList = new ArrayList(); 15 | int N = scan.nextInt(); 16 | String n = scan.nextLine(); 17 | for (int i = 0; i < N; i++) { 18 | String tmp = scan.nextLine(); 19 | arrayList.add(tmp); 20 | } 21 | 22 | for (int i = 0; i < N; i++) { 23 | stack.clear(); 24 | for (int j = 0; j < arrayList.get(i).length(); j++) { 25 | if (arrayList.get(i).charAt(j) == '(') { 26 | stack.add(arrayList.get(i).charAt(j)); 27 | } 28 | else if(arrayList.get(i).charAt(j) == ')') { 29 | if(!stack.empty() && stack.peek().equals('(')) { 30 | stack.pop(); 31 | } 32 | else { 33 | stack.add(arrayList.get(i).charAt(j)); 34 | break; 35 | } 36 | } 37 | } 38 | if(!stack.empty()) { 39 | System.out.println("NO"); 40 | } 41 | else { 42 | System.out.println("YES"); 43 | } 44 | } 45 | 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /Jin/sw_1952_수영장.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.Scanner; 3 | 4 | public class Main { 5 | 6 | static class testcase{ 7 | ArrayList price = new ArrayList<>(); 8 | ArrayList month = new ArrayList<>(); 9 | 10 | } 11 | 12 | static int min; 13 | 14 | public static void main(String[] args) { 15 | // TODO Auto-generated method stub 16 | int N = 0; 17 | Scanner in = new Scanner(System.in); 18 | N = in.nextInt(); 19 | min = 0; 20 | 21 | ArrayList tc = new ArrayList<>(); 22 | 23 | for(int i=0;i= t.price.get(3)) { 45 | min = t.price.get(3); 46 | } 47 | 48 | System.out.println("#" + s + " " + min); 49 | } 50 | } 51 | 52 | public static void dfs(testcase t, int count, int num) { 53 | if(num <= 11) { 54 | count += t.month.get(num) * t.price.get(0); 55 | dfs(t, count, num+1); 56 | count -= t.month.get(num) * t.price.get(0); 57 | 58 | 59 | if(t.month.get(num)!=0) { 60 | count += t.price.get(1); 61 | dfs(t, count, num+1); 62 | count -= t.price.get(1); 63 | } 64 | 65 | if(num<=9) { 66 | if(t.month.get(num)!=0 || t.month.get(num+1)!=0 || t.month.get(num+2)!=0) { 67 | count += t.price.get(2); 68 | dfs(t, count, num+3); 69 | count -= t.price.get(2); 70 | } 71 | return; 72 | } 73 | else return; 74 | } 75 | 76 | if (min >= count && num == 12) { 77 | min = count; 78 | } 79 | 80 | //count = 0; 81 | 82 | return; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /Jin/색종이.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.Arrays; 3 | import java.util.Scanner; 4 | 5 | public class Main { 6 | 7 | static class point { 8 | int x; 9 | int y; 10 | 11 | point(int x, int y){ 12 | this.x = x; 13 | this.y = y; 14 | } 15 | } 16 | 17 | static int[][] map; 18 | static int[][] buf; 19 | static int onenum; 20 | 21 | 22 | public static void main(String[] args) { 23 | // TODO Auto-generated method stub 24 | map = new int[10][10]; 25 | buf = new int[10][10]; 26 | 27 | Scanner in = new Scanner(System.in); 28 | onenum = 0; 29 | 30 | for(int i=0;i<10;i++) { 31 | for(int j = 0;j<10;j++) { 32 | buf[i][j] = in.nextInt(); 33 | if(buf[i][j] == 1) onenum++; 34 | } 35 | } 36 | 37 | for(int i=0;i<10;i++) { 38 | for(int j = 0;j<10;j++) { 39 | map[i][j] = buf[i][j]; 40 | } 41 | } 42 | in.close(); 43 | 44 | int fnum=5, snum=5, tnum=5, fonum = 5, finum = 5; 45 | int result = 0; 46 | 47 | while(onenum > 0) { 48 | int count = findArea(); 49 | 50 | if(count == 1) fnum--; 51 | else if(count == 2) snum--; 52 | else if(count == 3) tnum--; 53 | else if(count == 4) fonum--; 54 | else if(count == 5) finum--; 55 | 56 | if(fnum<0||snum<0||tnum<0||fonum<0||finum<0) { 57 | result = -1; 58 | break; 59 | } 60 | onenum = onenum - (count * count); 61 | result++; 62 | } 63 | 64 | System.out.println(result); 65 | 66 | 67 | } 68 | 69 | 70 | public static int findArea() { 71 | int max = 0; 72 | int num = 0; 73 | 74 | point p = new point(0,0); 75 | 76 | for(int i = 0;i<10;i++) { 77 | for(int j=0;j<10;j++) { 78 | if(map[i][j] == 1) { 79 | num = check(i,j); 80 | if(num > 5) { 81 | num = (num+1)/2; 82 | } 83 | if(max <= num) { 84 | max = num; 85 | p.x = i; 86 | p.y = j; 87 | } 88 | } 89 | } 90 | } 91 | 92 | 93 | for(int i=p.x;i arr = new ArrayList(); 44 | arr.add(D); 45 | 46 | for(int i = 0; i < G; i++) { 47 | ArrayList buffer = new ArrayList(); 48 | 49 | for(int j = arr.size()-1 ; j >= 0; j--) { 50 | if(arr.get(j)==0) { 51 | buffer.add(1); 52 | } 53 | else if(arr.get(j)==1) { 54 | buffer.add(2); 55 | } 56 | else if(arr.get(j)==2) { 57 | buffer.add(3); 58 | } 59 | else if(arr.get(j)==3) { 60 | buffer.add(0); 61 | } 62 | } 63 | 64 | for(int k = 0; k100 || x <0 || y>100 || y<0) { 87 | break; 88 | } 89 | 90 | result[x][y] = 1; 91 | } 92 | 93 | } 94 | 95 | public static int find_function() { 96 | int rst = 0; 97 | for(int i = 0 ; i <100; i++) { 98 | for(int j = 0 ; j <100; j++) { 99 | if(result[i][j]==1 &&result[i+1][j]==1 && result[i][j+1]==1 && result[i+1][j+1]==1) { 100 | rst++; 101 | } 102 | } 103 | } 104 | 105 | return rst; 106 | } 107 | 108 | } 109 | -------------------------------------------------------------------------------- /JuRyun/2583_영역구하기.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.Collections; 3 | import java.util.Scanner; 4 | 5 | public class Main { 6 | 7 | static int[][] result = new int[101][101]; 8 | static int M = 0; 9 | static int N = 0; 10 | static int K = 0; 11 | static int[] X1 = new int[100]; 12 | static int[] Y1 = new int[100]; 13 | static int[] X2 = new int[100]; 14 | static int[] Y2 = new int[100]; 15 | 16 | public static void main(String[] args) { 17 | // TODO Auto-generated method stub 18 | int max = 0; 19 | int flag = 0; 20 | Scanner input = new Scanner(System.in); 21 | M = input.nextInt(); 22 | N = input.nextInt(); 23 | K = input.nextInt(); 24 | 25 | for (int i = 0; i < K; i++) { 26 | X1[i] = input.nextInt(); 27 | Y1[i] = input.nextInt(); 28 | X2[i] = input.nextInt(); 29 | Y2[i] = input.nextInt(); 30 | } 31 | input.close(); 32 | 33 | int[][] arr = new int[M][N]; 34 | for (int i = 0; i < M; i++) { 35 | for (int j = 0; j < N; j++) { 36 | arr[i][j] = 0; 37 | } 38 | } 39 | 40 | for (int i = 0; i < K; i++) { 41 | for (int j = X1[i]; j < X2[i]; j++) { 42 | for (int k = Y1[i]; k < Y2[i]; k++) { 43 | arr[k][j] = 101; 44 | } 45 | } 46 | } 47 | 48 | for (int i = 1; i <= 9999; i++) { 49 | flag = 0; 50 | for (int j = 0; j < M; j++) { 51 | for (int k = 0; k < N; k++) { 52 | if (arr[j][k] == 0) { 53 | flag++; 54 | } 55 | } 56 | } 57 | 58 | if (flag == 0) { 59 | break; 60 | } 61 | int brk = 0; 62 | for (int j = 0; j < M; j++) { 63 | for (int k = 0; k < N; k++) { 64 | if (arr[j][k] == 0) { 65 | arr[j][k] = i; 66 | max++; 67 | brk = 1; 68 | break; 69 | } 70 | } 71 | if (brk == 1) { 72 | break; 73 | } 74 | } 75 | 76 | for (int j = 0; j < M; j++) { 77 | for (int k = 0; k < N; k++) { 78 | if (arr[j][k] == i) { 79 | if (j != M - 1) { 80 | if (arr[j + 1][k] == 0) { 81 | arr[j + 1][k] = i; 82 | } 83 | } 84 | if (j != 0) { 85 | if (arr[j - 1][k] == 0) { 86 | arr[j - 1][k] = i; 87 | } 88 | } 89 | if (k != N - 1) { 90 | if (arr[j][k + 1] == 0) { 91 | arr[j][k + 1] = i; 92 | } 93 | } 94 | if (k != 0) { 95 | if (arr[j][k - 1] == 0) { 96 | arr[j][k - 1] = i; 97 | } 98 | } 99 | } 100 | } 101 | } 102 | 103 | for (int k = 0; k < N; k++) { 104 | for (int j = 0; j < M; j++) { 105 | if (arr[j][k] == i) { 106 | if (j != M - 1) { 107 | if (arr[j + 1][k] == 0) { 108 | arr[j + 1][k] = i; 109 | } 110 | } 111 | if (j != 0) { 112 | if (arr[j - 1][k] == 0) { 113 | arr[j - 1][k] = i; 114 | } 115 | } 116 | if (k != N - 1) { 117 | if (arr[j][k + 1] == 0) { 118 | arr[j][k + 1] = i; 119 | } 120 | } 121 | if (k != 0) { 122 | if (arr[j][k - 1] == 0) { 123 | arr[j][k - 1] = i; 124 | } 125 | } 126 | } 127 | } 128 | } 129 | 130 | for (int k = N-1; k > 0; k--) { 131 | for (int j = M-1; j > 0; j--) { 132 | if (arr[j][k] == i) { 133 | if (j != M - 1) { 134 | if (arr[j + 1][k] == 0) { 135 | arr[j + 1][k] = i; 136 | } 137 | } 138 | if (j != 0) { 139 | if (arr[j - 1][k] == 0) { 140 | arr[j - 1][k] = i; 141 | } 142 | } 143 | if (k != N - 1) { 144 | if (arr[j][k + 1] == 0) { 145 | arr[j][k + 1] = i; 146 | } 147 | } 148 | if (k != 0) { 149 | if (arr[j][k - 1] == 0) { 150 | arr[j][k - 1] = i; 151 | } 152 | } 153 | } 154 | } 155 | } 156 | 157 | 158 | for (int j = M - 1; j >= 0; j--) { 159 | for (int k = N - 1; k >= 0; k--) { 160 | if (arr[j][k] == i) { 161 | if (j != M - 1) { 162 | if (arr[j + 1][k] == 0) { 163 | arr[j + 1][k] = i; 164 | } 165 | } 166 | if (j != 0) { 167 | if (arr[j - 1][k] == 0) { 168 | arr[j - 1][k] = i; 169 | } 170 | } 171 | if (k != N - 1) { 172 | if (arr[j][k + 1] == 0) { 173 | arr[j][k + 1] = i; 174 | } 175 | } 176 | if (k != 0) { 177 | if (arr[j][k - 1] == 0) { 178 | arr[j][k - 1] = i; 179 | } 180 | } 181 | } 182 | } 183 | } 184 | 185 | } 186 | 187 | int[] result = new int[max]; 188 | for (int i = 0; i < max; i++) { 189 | result[i] = 0; 190 | } 191 | 192 | for (int i = 0; i < max; i++) { 193 | for (int j = 0; j < M; j++) { 194 | for (int k = 0; k < N; k++) { 195 | if (arr[j][k] == i + 1) { 196 | result[i]++; 197 | } 198 | } 199 | } 200 | } 201 | 202 | ArrayList arrlist = new ArrayList(); 203 | for (int i = 0; i < max; i++) { 204 | arrlist.add(result[i]); 205 | } 206 | Collections.sort(arrlist); 207 | 208 | System.out.println(max); 209 | for (int i = 0; i < max; i++) { 210 | System.out.print(arrlist.get(i)); 211 | System.out.print(" "); 212 | 213 | } 214 | 215 | } 216 | 217 | } 218 | -------------------------------------------------------------------------------- /JuRyun/7562_나이트의이동.java: -------------------------------------------------------------------------------- 1 | import java.util.LinkedList; 2 | import java.util.Queue; 3 | import java.util.Scanner; 4 | 5 | public class Main { 6 | 7 | static class Point{ 8 | Point(int x, int y){ 9 | this.x = x; 10 | this.y = y; 11 | } 12 | Point() { 13 | // TODO Auto-generated constructor stub 14 | } 15 | int x ; 16 | int y ; 17 | } 18 | 19 | static int[] dx = {-2, -2, -1, -1, 2, 2, 1, 1}; 20 | static int[] dy = {-1, 1, 2, -2, -1, 1, 2, -2}; 21 | 22 | 23 | public static void main(String[] args) { 24 | // TODO Auto-generated method stub 25 | int testCount = 0; 26 | 27 | Scanner input = new Scanner(System.in); 28 | 29 | testCount = input.nextInt(); 30 | int[] length = new int[testCount]; 31 | Point[] startPoint = new Point[testCount]; 32 | Point[] endPoint = new Point[testCount]; 33 | 34 | for(int i = 0 ; i < testCount; i ++) { 35 | startPoint[i] = new Point(); 36 | endPoint[i] = new Point(); 37 | length[i] = input.nextInt(); 38 | startPoint[i].x = input.nextInt(); 39 | startPoint[i].y = input.nextInt(); 40 | endPoint[i].x = input.nextInt(); 41 | endPoint[i].y = input.nextInt(); 42 | } 43 | 44 | for(int i = 0; i < testCount; i++) { 45 | System.out.println(bfs(length[i], startPoint[i], endPoint[i])); 46 | } 47 | 48 | 49 | } 50 | 51 | static int bfs(int length, Point startPoint, Point endPoint) { 52 | int count = 0; 53 | int[][] Map = new int[length][length]; 54 | for(int i = 0 ; i < length; i++) { 55 | for(int j = 0 ; j < length; j ++) { 56 | Map[i][j] = 999; 57 | } 58 | } 59 | 60 | Queue queue = new LinkedList<>(); 61 | queue.offer(startPoint); 62 | Map[startPoint.y][startPoint.x] = 0; 63 | 64 | if(startPoint.x == endPoint.x && startPoint.y == endPoint.y) { 65 | return 0; 66 | } 67 | 68 | Point PopedPoint = new Point(); 69 | PopedPoint.x = 999; 70 | PopedPoint.y = 999; 71 | while(PopedPoint.x != endPoint.x || PopedPoint.y != endPoint.y ) { 72 | PopedPoint = queue.poll(); 73 | count = Map[PopedPoint.y][PopedPoint.x] +1; 74 | 75 | for(int i = 0; i < 8; i++) { 76 | Point pnt = new Point(PopedPoint.x+dx[i],PopedPoint.y+dy[i]); 77 | if(pnt.x >=0 && pnt.y>=0 && pnt.x = 0) { 65 | if(map[x-1][y] != true) { 66 | Search(x - 1, y); 67 | } 68 | } 69 | 70 | if(y + 1 < M) { 71 | if(map[x][y+1] != true) { 72 | Search(x, y + 1); 73 | } 74 | } 75 | 76 | if(y - 1 >= 0) { 77 | if(map[x][y-1] != true) { 78 | Search(x, y - 1); 79 | } 80 | } 81 | 82 | return area; 83 | } 84 | } 85 | 86 | -------------------------------------------------------------------------------- /LimGeon/6593_LimGeon.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | typedef struct cur { 7 | int z, y, x, cnt; 8 | }cur; 9 | 10 | queue q; 11 | 12 | int dx[] = { 1,-1,0,0,0,0 }; 13 | int dy[] = { 0,0,1,-1,0,0 }; 14 | int dz[] = { 0,0,0,0,1,-1 }; 15 | 16 | int visited[30][30][31]; 17 | 18 | int main() 19 | { 20 | int l, r, c; 21 | char map[30][30][31]; 22 | 23 | while (1) { 24 | scanf("%d %d %d", &l, &r, &c); 25 | if (l == 0 && r == 0 && c == 0) break; 26 | for (int i = 0; i < l; i++) { 27 | for (int j = 0; j < r; j++) { 28 | scanf("%s", map[i][j]); 29 | 30 | } 31 | } 32 | 33 | int flag = 0; 34 | for (int i = 0; i < l; i++) { 35 | for (int j = 0; j < r; j++) { 36 | for (int k = 0; k < c; k++) { 37 | if (map[i][j][k] == 'S') { 38 | cur start = { i,j,k,0 }; 39 | q.push(start); 40 | while (!q.empty() && flag == 0) { 41 | cur now = q.front(); 42 | q.pop(); 43 | for (int m = 0; m < 6; m++) { 44 | cur next = { now.z + dz[m],now.y + dy[m],now.x + dx[m],now.cnt + 1 }; 45 | if (0 <= next.z && next.z < l && 0 <= next.y && next.y < r && 0 <= next.x && next.x < c) { 46 | if (visited[next.z][next.y][next.x]==0 && map[next.z][next.y][next.x] != '#') { 47 | visited[next.z][next.y][next.x] = 1; 48 | if (map[next.z][next.y][next.x] == 'E') { 49 | printf("Escaped in %d minute(s).\n", next.cnt); 50 | flag = 1; 51 | } 52 | q.push(next); 53 | } 54 | } 55 | } 56 | } 57 | } 58 | } 59 | } 60 | } 61 | while (!q.empty()) q.pop(); 62 | for (int i = 0; i < l; i++) { 63 | for (int j = 0; j < r; j++) { 64 | for (int k = 0; k < c; k++) 65 | visited[i][j][k] = 0; 66 | } 67 | } 68 | if(flag==0) printf("Trapped!\n"); 69 | } 70 | return 0; 71 | } -------------------------------------------------------------------------------- /LimGeon/LimGeon_1018.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | char board[50][51]; 7 | 8 | int main() { 9 | 10 | //input 11 | int n, m; 12 | scanf("%d %d", &n, &m); 13 | for (int i = 0; i < n; i++) 14 | scanf("%s", board[i]); 15 | 16 | //process 17 | int minColor = 1e9; 18 | for (int i = 0; i + 7 < n; i++) { 19 | for (int j = 0; j + 7 < m; j++) { 20 | int sum1[2] = { 0, }; //idx 0: W sum idx 1: B sum 21 | int sum2[2] = { 0, }; //idx 0: W sum idx 1: B sum 22 | for (int k = i; k < i + 8; k++) { 23 | for (int l = j; l < j + 8; l++) { 24 | if ((k + l) % 2 == 0) { 25 | if(board[k][l]=='W') sum1[0] += (int)board[k][l]; 26 | else if (board[k][l] == 'B') sum1[1] += (int)board[k][l]; 27 | } 28 | else { 29 | if (board[k][l] == 'W') sum2[0] += (int)board[k][l]; 30 | else if (board[k][l] == 'B') sum2[1] += (int)board[k][l]; 31 | } 32 | } 33 | } 34 | 35 | int wsum = (int)'W' * 32; 36 | int bsum = (int)'B' * 32; 37 | int caseA = (32 - (wsum - sum1[0]) / 'W') + (32 - (bsum - sum2[1]) / 'B'); 38 | int caseB = (32 - (wsum - sum2[0]) / 'W') + (32 - (bsum - sum1[1]) / 'B'); 39 | int tmp = min(caseA, caseB); 40 | minColor = min(minColor, tmp); 41 | } 42 | } 43 | printf("%d", minColor); 44 | return 0; 45 | } -------------------------------------------------------------------------------- /MINWOOK/15683-윤민욱.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.Scanner; 3 | 4 | public class Solution { 5 | 6 | private static final int UP = 0; 7 | private static final int RIGHT = 1; 8 | private static final int DOWN = 2; 9 | private static final int LEFT = 3; 10 | private static final int WALL = 6; 11 | private static final int MAX = 4; 12 | 13 | public static int[][] office; 14 | public static int n, m; 15 | public static int min = Integer.MAX_VALUE; 16 | 17 | public static class CCTV { 18 | 19 | int x, y; 20 | int type; 21 | boolean[] directionList; 22 | 23 | public CCTV(int x, int y, int type) { 24 | 25 | this.x = x; 26 | this.y = y; 27 | this.type = type; 28 | this.directionList = new boolean[MAX]; 29 | this.initialize(); 30 | } 31 | 32 | public void initialize() { 33 | 34 | if (this.type == 1) { 35 | 36 | directionList[UP] = true; 37 | } else if (this.type == 2) { 38 | 39 | directionList[LEFT] = true; 40 | directionList[RIGHT] = true; 41 | } else if (this.type == 3) { 42 | 43 | directionList[UP] = true; 44 | directionList[RIGHT] = true; 45 | } else if (this.type == 4) { 46 | 47 | directionList[LEFT] = true; 48 | directionList[UP] = true; 49 | directionList[RIGHT] = true; 50 | } else { 51 | 52 | for (int i = 0; i < this.directionList.length; i++) 53 | directionList[i] = true; 54 | } 55 | } 56 | 57 | public void rotate() { 58 | 59 | boolean temp = this.directionList[LEFT]; 60 | this.directionList[LEFT] = this.directionList[DOWN]; 61 | this.directionList[DOWN] = this.directionList[RIGHT]; 62 | this.directionList[RIGHT] = this.directionList[UP]; 63 | this.directionList[UP] = temp; 64 | } 65 | 66 | public boolean[][] inspection(boolean[][] isInspected) { 67 | 68 | boolean[][] result = new boolean[n][m]; 69 | 70 | for (int i = 0; i < n; i++) 71 | for (int j = 0; j < m; j++) 72 | result[i][j] = isInspected[i][j]; 73 | 74 | if (this.directionList[0]) { 75 | for (int i = x; i >= 0; i--) { 76 | if (office[i][y] == WALL) 77 | break; 78 | 79 | result[i][y] = true; 80 | } 81 | } 82 | if (this.directionList[1]) { 83 | for (int i = y; i < m; i++) { 84 | if (office[x][i] == WALL) 85 | break; 86 | 87 | result[x][i] = true; 88 | } 89 | } 90 | if (this.directionList[2]) { 91 | for (int i = x; i < n; i++) { 92 | if (office[i][y] == WALL) 93 | break; 94 | 95 | result[i][y] = true; 96 | } 97 | } 98 | if (this.directionList[3]) { 99 | for (int i = y; i >= 0; i--) { 100 | if (office[x][i] == WALL) 101 | break; 102 | 103 | result[x][i] = true; 104 | } 105 | } 106 | 107 | return result; 108 | } 109 | } 110 | 111 | public static void main(String[] args) { 112 | // TODO Auto-generated method stub 113 | 114 | @SuppressWarnings("resource") 115 | Scanner sc = new Scanner(System.in); 116 | 117 | n = sc.nextInt(); 118 | m = sc.nextInt(); 119 | 120 | office = new int[n][m]; 121 | ArrayList cctvList = new ArrayList(); 122 | boolean[][] isInspected = new boolean[n][m]; 123 | 124 | for (int i = 0; i < n; i++) { 125 | for (int j = 0; j < m; j++) { 126 | 127 | int input = sc.nextInt(); 128 | if (input == WALL) { 129 | isInspected[i][j] = true; 130 | } 131 | office[i][j] = input; 132 | if (input > 0 && input != WALL) { 133 | cctvList.add(new CCTV(i, j, input)); 134 | } 135 | } 136 | } 137 | 138 | solution(cctvList, isInspected, 0); 139 | System.out.println(min); 140 | } 141 | 142 | public static void solution(ArrayList cctvList, boolean[][] isInspected, int index) { 143 | 144 | if (index == cctvList.size()) { 145 | 146 | int sum = 0; 147 | for (int i = 0; i < n; i++) { 148 | for (int j = 0; j < m; j++) { 149 | if (!isInspected[i][j]) { 150 | sum++; 151 | } 152 | 153 | } 154 | } 155 | 156 | if (sum < min) { 157 | min = sum; 158 | } 159 | return; 160 | } 161 | 162 | CCTV cctv = cctvList.get(index); 163 | 164 | for (int i = 0; i < 4; i++) { 165 | 166 | boolean[][] temp = cctv.inspection(isInspected); 167 | solution(cctvList, temp, index + 1); 168 | 169 | cctv.rotate(); 170 | } 171 | 172 | } 173 | 174 | } 175 | -------------------------------------------------------------------------------- /MINWOOK/2583-윤민욱.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.ArrayList; 3 | import java.util.Collections; 4 | import java.util.Scanner; 5 | 6 | public class Main { 7 | 8 | private static final int BLOCKED = -1; 9 | private static final int UNVISITED = 0; 10 | private static final int VISITED = 1; 11 | 12 | public static int m, n, k; 13 | public static int[][] coordinate; 14 | public static boolean[][] isVisited; 15 | public static ArrayList areaList; 16 | public static int area = 0; 17 | 18 | public static void main(String[] args) { 19 | // TODO Auto-generated method stub 20 | 21 | Scanner sc = new Scanner(System.in); 22 | 23 | m = sc.nextInt(); 24 | n = sc.nextInt(); 25 | k = sc.nextInt(); 26 | coordinate = new int[m][n]; 27 | isVisited = new boolean[m][n]; 28 | areaList = new ArrayList(); 29 | 30 | while (k > 0) { 31 | 32 | boolean[][] isVisited = new boolean[m][n]; 33 | int i = sc.nextInt(); 34 | int j = sc.nextInt(); 35 | int x = sc.nextInt(); 36 | int y = sc.nextInt(); 37 | dfs(j, i, y, x, isVisited); 38 | k--; 39 | } 40 | 41 | int count = 0; 42 | for (int i = 0; i < m; i++) { 43 | for (int j = 0; j < n; j++) { 44 | 45 | if (coordinate[i][j] != BLOCKED && !isVisited[i][j]) { 46 | 47 | solution(i, j); 48 | areaList.add(area); 49 | area = 0; 50 | count++; 51 | } 52 | } 53 | } 54 | 55 | Collections.sort(areaList); 56 | System.out.println(count); 57 | for(int i : areaList) 58 | System.out.print(i + " "); 59 | 60 | } 61 | 62 | public static void dfs(int i, int j, int x, int y, boolean[][] isVisited) { 63 | 64 | coordinate[i][j] = BLOCKED; 65 | isVisited[i][j] = true; 66 | 67 | if (i + 1 < x && !isVisited[i + 1][j]) { 68 | 69 | dfs(i + 1, j, x, y, isVisited); 70 | } 71 | if (j + 1 < y && !isVisited[i][j + 1]) { 72 | 73 | dfs(i, j + 1, x, y, isVisited); 74 | } 75 | } 76 | 77 | public static void solution(int x, int y) { 78 | 79 | area++; 80 | isVisited[x][y] = true; 81 | coordinate[x][y] = VISITED; 82 | 83 | if (x + 1 < m && coordinate[x + 1][y] != BLOCKED && !isVisited[x + 1][y]) { 84 | 85 | solution(x + 1, y); 86 | } 87 | if (x - 1 >= 0 && coordinate[x - 1][y] != BLOCKED && !isVisited[x - 1][y]) { 88 | 89 | solution(x - 1, y); 90 | } 91 | if (y + 1 < n && coordinate[x][y + 1] != BLOCKED && !isVisited[x][y + 1]) { 92 | 93 | solution(x, y + 1); 94 | } 95 | if (y - 1 >= 0 && coordinate[x][y - 1] != BLOCKED && !isVisited[x][y - 1]) { 96 | 97 | solution(x, y - 1); 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /PJH/1018_체스판다시칠하기.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | int M = input.nextInt(); 7 | int N = input.nextInt(); 8 | int Min = 9999; 9 | 10 | String input_str[] = new String[M]; 11 | char map[][] = new char[M][N]; 12 | for(int i = 0; i < M ; i ++){ 13 | input_str[i] = input.next(); 14 | } 15 | 16 | for(int i = 0 ; i < M ; i ++){ 17 | for(int j = 0 ; j < N ; j ++){ 18 | map[i][j] = input_str[i].charAt(j); 19 | } 20 | } 21 | 22 | for(int i = 0 ; i <= M -8; i ++){ 23 | for(int j = 0 ; j <= N-8; j ++){ 24 | int countA = 0; 25 | int countB = 0; 26 | for(int k = i ; k < i+8; k ++){ 27 | for(int z = j ; z < j+8; z++){ 28 | if((k+z)%2 == 0 && map[k][z] != 'W'){ 29 | countA++; 30 | } 31 | else if((k+z)%2 == 1 && map[k][z] != 'B'){ 32 | countA++; 33 | } 34 | } 35 | if(countA>Min){ 36 | break; 37 | } 38 | } 39 | for(int k = i ; k < i+8; k ++){ 40 | for(int z = j ; z < j+8; z++){ 41 | if((k+z)%2 == 0 && map[k][z] != 'B'){ 42 | countB++; 43 | } 44 | else if((k+z)%2 == 1 && map[k][z] != 'W'){ 45 | countB++; 46 | } 47 | } 48 | if(countB>Min){ 49 | break; 50 | } 51 | } 52 | 53 | if(countA >= countB && Min > countB){ 54 | Min = countB; 55 | } 56 | else if(countB > countA && Min > countA){ 57 | Min = countA; 58 | } 59 | } 60 | } 61 | 62 | System.out.print(Min); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /PJH/14501_퇴사.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/git-tturami/algorithm/aa61bdfa3d41f33dcf70c79ceb3c139a46fb6008/PJH/14501_퇴사.java -------------------------------------------------------------------------------- /PJH/15685_드래곤커브.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.Scanner; 3 | 4 | public class Main { 5 | 6 | static int[][] result = new int[101][101]; 7 | static int N = 0; 8 | static int[] X = new int[20]; 9 | static int[] Y = new int[20]; 10 | static int[] D = new int[20]; 11 | static int[] G = new int[20]; 12 | 13 | public static void main(String[] args) { 14 | // TODO Auto-generated method stub 15 | int total=0; 16 | Scanner input = new Scanner(System.in); 17 | N = input.nextInt(); 18 | 19 | for(int i = 0 ; i < N ; i++) { 20 | X[i] = input.nextInt(); 21 | Y[i] = input.nextInt(); 22 | D[i] = input.nextInt(); 23 | G[i] = input.nextInt(); 24 | } 25 | input.close(); 26 | 27 | for(int i = 0 ; i < 101; i++) { 28 | for(int j = 0 ; j < 101; j++) { 29 | result[i][j] = 0; 30 | } 31 | } 32 | 33 | for(int i = 0; i< N; i++) { 34 | make_function(X[i], Y[i], D[i], G[i]); 35 | } 36 | 37 | total = find_function(); 38 | 39 | System.out.print(total); 40 | } 41 | 42 | public static void make_function(int X, int Y, int D, int G) { 43 | ArrayList arr = new ArrayList(); 44 | arr.add(D); 45 | 46 | for(int i = 0; i < G; i++) { 47 | ArrayList buffer = new ArrayList(); 48 | 49 | for(int j = arr.size()-1 ; j >= 0; j--) { 50 | if(arr.get(j)==0) { 51 | buffer.add(1); 52 | } 53 | else if(arr.get(j)==1) { 54 | buffer.add(2); 55 | } 56 | else if(arr.get(j)==2) { 57 | buffer.add(3); 58 | } 59 | else if(arr.get(j)==3) { 60 | buffer.add(0); 61 | } 62 | } 63 | 64 | for(int k = 0; k100 || x <0 || y>100 || y<0) { 87 | break; 88 | } 89 | 90 | result[x][y] = 1; 91 | } 92 | 93 | } 94 | 95 | public static int find_function() { 96 | int rst = 0; 97 | for(int i = 0 ; i <100; i++) { 98 | for(int j = 0 ; j <100; j++) { 99 | if(result[i][j]==1 &&result[i+1][j]==1 && result[i][j+1]==1 && result[i+1][j+1]==1) { 100 | rst++; 101 | } 102 | } 103 | } 104 | 105 | return rst; 106 | } 107 | 108 | } 109 | -------------------------------------------------------------------------------- /PJH/2583_영역구하기.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.Collections; 3 | import java.util.Scanner; 4 | 5 | public class Main { 6 | 7 | static int[][] result = new int[101][101]; 8 | static int M = 0; 9 | static int N = 0; 10 | static int K = 0; 11 | static int[] X1 = new int[100]; 12 | static int[] Y1 = new int[100]; 13 | static int[] X2 = new int[100]; 14 | static int[] Y2 = new int[100]; 15 | 16 | public static void main(String[] args) { 17 | // TODO Auto-generated method stub 18 | int max = 0; 19 | int flag = 0; 20 | Scanner input = new Scanner(System.in); 21 | M = input.nextInt(); 22 | N = input.nextInt(); 23 | K = input.nextInt(); 24 | 25 | for (int i = 0; i < K; i++) { 26 | X1[i] = input.nextInt(); 27 | Y1[i] = input.nextInt(); 28 | X2[i] = input.nextInt(); 29 | Y2[i] = input.nextInt(); 30 | } 31 | input.close(); 32 | 33 | int[][] arr = new int[M][N]; 34 | for (int i = 0; i < M; i++) { 35 | for (int j = 0; j < N; j++) { 36 | arr[i][j] = 0; 37 | } 38 | } 39 | 40 | for (int i = 0; i < K; i++) { 41 | for (int j = X1[i]; j < X2[i]; j++) { 42 | for (int k = Y1[i]; k < Y2[i]; k++) { 43 | arr[k][j] = 101; 44 | } 45 | } 46 | } 47 | 48 | for (int i = 1; i <= 9999; i++) { 49 | flag = 0; 50 | for (int j = 0; j < M; j++) { 51 | for (int k = 0; k < N; k++) { 52 | if (arr[j][k] == 0) { 53 | flag++; 54 | } 55 | } 56 | } 57 | 58 | if (flag == 0) { 59 | break; 60 | } 61 | int brk = 0; 62 | for (int j = 0; j < M; j++) { 63 | for (int k = 0; k < N; k++) { 64 | if (arr[j][k] == 0) { 65 | arr[j][k] = i; 66 | max++; 67 | brk = 1; 68 | break; 69 | } 70 | } 71 | if (brk == 1) { 72 | break; 73 | } 74 | } 75 | 76 | for (int j = 0; j < M; j++) { 77 | for (int k = 0; k < N; k++) { 78 | if (arr[j][k] == i) { 79 | if (j != M - 1) { 80 | if (arr[j + 1][k] == 0) { 81 | arr[j + 1][k] = i; 82 | } 83 | } 84 | if (j != 0) { 85 | if (arr[j - 1][k] == 0) { 86 | arr[j - 1][k] = i; 87 | } 88 | } 89 | if (k != N - 1) { 90 | if (arr[j][k + 1] == 0) { 91 | arr[j][k + 1] = i; 92 | } 93 | } 94 | if (k != 0) { 95 | if (arr[j][k - 1] == 0) { 96 | arr[j][k - 1] = i; 97 | } 98 | } 99 | } 100 | } 101 | } 102 | 103 | for (int k = 0; k < N; k++) { 104 | for (int j = 0; j < M; j++) { 105 | if (arr[j][k] == i) { 106 | if (j != M - 1) { 107 | if (arr[j + 1][k] == 0) { 108 | arr[j + 1][k] = i; 109 | } 110 | } 111 | if (j != 0) { 112 | if (arr[j - 1][k] == 0) { 113 | arr[j - 1][k] = i; 114 | } 115 | } 116 | if (k != N - 1) { 117 | if (arr[j][k + 1] == 0) { 118 | arr[j][k + 1] = i; 119 | } 120 | } 121 | if (k != 0) { 122 | if (arr[j][k - 1] == 0) { 123 | arr[j][k - 1] = i; 124 | } 125 | } 126 | } 127 | } 128 | } 129 | 130 | for (int k = N-1; k > 0; k--) { 131 | for (int j = M-1; j > 0; j--) { 132 | if (arr[j][k] == i) { 133 | if (j != M - 1) { 134 | if (arr[j + 1][k] == 0) { 135 | arr[j + 1][k] = i; 136 | } 137 | } 138 | if (j != 0) { 139 | if (arr[j - 1][k] == 0) { 140 | arr[j - 1][k] = i; 141 | } 142 | } 143 | if (k != N - 1) { 144 | if (arr[j][k + 1] == 0) { 145 | arr[j][k + 1] = i; 146 | } 147 | } 148 | if (k != 0) { 149 | if (arr[j][k - 1] == 0) { 150 | arr[j][k - 1] = i; 151 | } 152 | } 153 | } 154 | } 155 | } 156 | 157 | 158 | for (int j = M - 1; j >= 0; j--) { 159 | for (int k = N - 1; k >= 0; k--) { 160 | if (arr[j][k] == i) { 161 | if (j != M - 1) { 162 | if (arr[j + 1][k] == 0) { 163 | arr[j + 1][k] = i; 164 | } 165 | } 166 | if (j != 0) { 167 | if (arr[j - 1][k] == 0) { 168 | arr[j - 1][k] = i; 169 | } 170 | } 171 | if (k != N - 1) { 172 | if (arr[j][k + 1] == 0) { 173 | arr[j][k + 1] = i; 174 | } 175 | } 176 | if (k != 0) { 177 | if (arr[j][k - 1] == 0) { 178 | arr[j][k - 1] = i; 179 | } 180 | } 181 | } 182 | } 183 | } 184 | 185 | } 186 | 187 | int[] result = new int[max]; 188 | for (int i = 0; i < max; i++) { 189 | result[i] = 0; 190 | } 191 | 192 | for (int i = 0; i < max; i++) { 193 | for (int j = 0; j < M; j++) { 194 | for (int k = 0; k < N; k++) { 195 | if (arr[j][k] == i + 1) { 196 | result[i]++; 197 | } 198 | } 199 | } 200 | } 201 | 202 | ArrayList arrlist = new ArrayList(); 203 | for (int i = 0; i < max; i++) { 204 | arrlist.add(result[i]); 205 | } 206 | Collections.sort(arrlist); 207 | 208 | System.out.println(max); 209 | for (int i = 0; i < max; i++) { 210 | System.out.print(arrlist.get(i)); 211 | System.out.print(" "); 212 | 213 | } 214 | 215 | } 216 | 217 | } 218 | -------------------------------------------------------------------------------- /PJH/6593_상범빌딩.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/git-tturami/algorithm/aa61bdfa3d41f33dcf70c79ceb3c139a46fb6008/PJH/6593_상범빌딩.java -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Git-tturami 2 |



3 | `Git-tturami` is programming study group in Chung-Ang university computer science engineering.
4 | We pursue study for Mutual Benefit. so, Feel free debating each other.
5 | This repository is for algorithm study.
6 | 7 | ## For uploading your code 8 | * Please make your own directory and push your codes.
9 | * Upload your code after naming with `(ploblem's no)-(ploblem's name).cpp` like `1000-add.cpp`.
10 | * Make Pull request, and our member will review your code.
11 | 12 | ## Small rules for our study 13 | * Review other's code actively!! 14 | * Write commit-msg so we can understand well. 15 | * When you write comment in your Pull request, you should include about below ones, 16 | * My code's abstract `Time complexity`. 17 | * My code's abstract `Space complexity`. 18 | * What `algorithm`, `data structures` or `ways` I used. 19 | -------------------------------------------------------------------------------- /Taehong/14502-LabProblem.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.Scanner; 3 | 4 | public class Main { 5 | public static void main(String[] args) { 6 | Scanner sc = new Scanner(System.in); 7 | int N = sc.nextInt(); 8 | int M = sc.nextInt(); 9 | int[][] arr = new int[N][M]; 10 | for(int i = 0 ; i arrayList = new ArrayList<>(); 23 | for(int i = 0 ;ianswer) { 49 | answer = virus(temp, N, M); 50 | } 51 | } 52 | } 53 | } 54 | return answer; 55 | } 56 | public static int virus(int arr[][],int N,int M) 57 | { 58 | int count = 0 ; 59 | for(int k = 0 ;k 0){ 64 | if(arr[i - 1][j] == 0) { 65 | arr[i - 1][j] = 2; 66 | } 67 | } 68 | if (i < N - 1){ 69 | if(arr[i + 1][j] == 0) { 70 | arr[i + 1][j] = 2; 71 | } 72 | } 73 | if (j > 0) { 74 | if (arr[i][j - 1] == 0) { 75 | arr[i][j - 1] = 2; 76 | } 77 | } 78 | if (j < M - 1) { 79 | if (arr[i][j + 1] == 0) { 80 | arr[i][j + 1] = 2; 81 | } 82 | } 83 | } 84 | } 85 | } 86 | } 87 | for(int i = 0 ; i list= new ArrayList<>(); 13 | int[][] ladder = new int[N][M]; 14 | for(int i = 0;i0) 20 | { 21 | for(int i = 0 ;i=0;k--){ //역순으로 돌면서 드래곤 커브를 90씩 회전시켜준다 35 | curve[curve_size++] = (curve[k]+1)%4; // 기존에서 한칸을 더한게 90도 회전, 크기가 넘을경우 %4 36 | } 37 | } 38 | 39 | for (int j = 0 ; j= 101 || x<0 || x>101){ 43 | continue; 44 | } 45 | map[y][x] = 1; 46 | } 47 | } 48 | 49 | int result = 0; 50 | 51 | for(int y= 0; y<100; y++){ 52 | for(int x = 0; x<100; x++){ //조건에 맞는 사각형을 찾아서 일치할 경우 result의 값을 더해준다. 53 | if(map[y][x] == 1 && map[y][x+1] == 1 && map[y+1][x] == 1 && map[y+1][x+1] == 1){ 54 | result++; 55 | } 56 | } 57 | } 58 | System.out.println(result); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /git_tturami.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/git-tturami/algorithm/aa61bdfa3d41f33dcf70c79ceb3c139a46fb6008/git_tturami.png -------------------------------------------------------------------------------- /hyunsik/17135.cpp: -------------------------------------------------------------------------------- 1 | #pragma warning (disable:4996) 2 | #include 3 | using namespace std; 4 | 5 | int n, m, d, max = -1; 6 | int nEnemy = 0; 7 | 8 | int archers[3]; 9 | int willKill_r[3]; 10 | int willKill_c[3]; 11 | int map[16][16]; 12 | 13 | int simulate() { 14 | int buf[16][16]; 15 | for (int r = 0; r < 16; r++) { 16 | for (int c = 0; c < 16; c++) { 17 | buf[r][c] = map[r][c]; 18 | } 19 | } 20 | 21 | int turn = 0; 22 | int died = 0; 23 | int killed = 0; 24 | while (killed + died < nEnemy) { 25 | willKill_r[0] = willKill_r[1] = willKill_r[2] = -1; 26 | willKill_c[0] = willKill_c[1] = willKill_c[2] = -1; 27 | for (int i = 0; i<3; i++) { 28 | int minDist = 99; 29 | for (int r = 0;r < n;r++) { 30 | for (int c = 0;c < m;c++) { 31 | if (buf[r][c] == 1) { 32 | 33 | int dr = n - r; 34 | int dc = archers[i] - c; 35 | if (dc < 0) dc = -dc; 36 | 37 | int dist = dr + dc; 38 | if (dist <= d && dist <= minDist) { 39 | if (dist == minDist) { 40 | if (c < willKill_c[i]) { 41 | willKill_r[i] = r; 42 | willKill_c[i] = c; 43 | minDist = dist; 44 | } 45 | } 46 | else { 47 | willKill_r[i] = r; 48 | willKill_c[i] = c; 49 | minDist = dist; 50 | } 51 | } 52 | } 53 | } 54 | } 55 | } 56 | 57 | for (int i = 0; i < 3; i++) { 58 | if (willKill_r[i] != -1 && buf[willKill_r[i]][willKill_c[i]] == 1) { 59 | killed++; 60 | buf[willKill_r[i]][willKill_c[i]] = 0; 61 | } 62 | } 63 | 64 | 65 | for (int r = n - 1;r >= 0;r--) { 66 | for (int c = 0; c < m; c++) { 67 | if (buf[r][c] == 1) { 68 | buf[r + 1][c] = 1; 69 | buf[r][c] = 0; 70 | if (r + 1 == n) { 71 | buf[r + 1][c] = 0; 72 | died++; 73 | } 74 | } 75 | } 76 | } 77 | } 78 | return killed; 79 | } 80 | 81 | void dfs(int idx, int cnt) { 82 | if (idx >= m) { 83 | return; 84 | } 85 | 86 | archers[cnt] = idx; 87 | if (cnt == 2) { 88 | int ans = simulate(); 89 | if (max <= ans) { 90 | max = ans; 91 | } 92 | return; 93 | } 94 | for (int i = idx + 1; i 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int price[4] = {0, 0, 0, 0}; 8 | int plan[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; 9 | int minPrice; 10 | 11 | void solve(int m, int cost); 12 | 13 | int main(void) { 14 | int T; 15 | scanf("%d", &T); 16 | for (int i = 0; i < T; i++) { 17 | for (int j = 0; j < 4; j++) { 18 | scanf("%d", &price[j]); 19 | } 20 | 21 | for (int j = 0; j < 12; j++) { 22 | scanf("%d", &plan[j]); 23 | } 24 | 25 | minPrice = price[3]; 26 | solve(0, 0); 27 | 28 | printf("#%d %d\n", i + 1, minPrice); 29 | } 30 | 31 | return 0; 32 | } 33 | 34 | void solve(int m, int cost) { 35 | if (m >= 12) { 36 | if (cost < minPrice) { 37 | minPrice = cost; 38 | } 39 | 40 | return; 41 | } 42 | 43 | if (plan[m] == 0) { 44 | solve(m + 1, cost); 45 | } 46 | 47 | // 3 month 48 | solve(m + 3, cost + price[2]); 49 | // 1 month 50 | solve(m + 1, cost + price[1]); 51 | // 1 day 52 | solve(m + 1, cost + price[0] * plan[m]); 53 | } 54 | -------------------------------------------------------------------------------- /junhuikim/7562-나이트의이동.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int dr[8] = {-1, -2, -2, -1, 1, 2, 2, 1}; 8 | int dc[8] = {-2, -1, 1, 2, 2, 1, -1, -2}; 9 | 10 | int map[300][300]; 11 | 12 | struct position { 13 | int row; 14 | int col; 15 | 16 | int time; 17 | }; 18 | 19 | queue q; 20 | 21 | void init() { 22 | for (int i = 0; i < 300; i++) { 23 | for (int j = 0; j < 300; j++) { 24 | map[i][j] = 0; 25 | } 26 | } 27 | 28 | while (!q.empty()) { 29 | q.pop(); 30 | } 31 | } 32 | 33 | int main(void) { 34 | int T = 0; 35 | 36 | int mapSize, kRow, kCol, dstRow, dstCol; 37 | 38 | cin >> T; 39 | 40 | for (int test = 0; test < T; test++) { 41 | init(); 42 | 43 | cin >> mapSize >> kRow >> kCol >> dstRow >> dstCol; 44 | 45 | q.push({kRow, kCol, 0}); 46 | 47 | map[kRow][kCol]++; 48 | 49 | while (!q.empty()) { 50 | position pos = q.front(); 51 | q.pop(); 52 | 53 | if (pos.row == dstRow && pos.col == dstCol) { 54 | cout << pos.time << endl; 55 | break; 56 | } 57 | 58 | for (int i = 0; i < 8; i++) { 59 | int nextRow = pos.row + dr[i]; 60 | int nextCol = pos.col + dc[i]; 61 | 62 | if (nextRow >= 0 && nextRow < mapSize && nextCol >= 0 && nextCol < mapSize) { 63 | if (map[nextRow][nextCol] == 0) { 64 | q.push({nextRow, nextCol, pos.time + 1}); 65 | map[nextRow][nextCol]++; 66 | } 67 | } 68 | } 69 | } 70 | } 71 | 72 | return 0; 73 | } 74 | -------------------------------------------------------------------------------- /junhuikim/README.md: -------------------------------------------------------------------------------- 1 | junhui820@gmail.com 2 | 3 | github.com/hihiboss 4 | -------------------------------------------------------------------------------- /minji/2583-영역구하기.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/git-tturami/algorithm/aa61bdfa3d41f33dcf70c79ceb3c139a46fb6008/minji/2583-영역구하기.cpp -------------------------------------------------------------------------------- /mose/1952-수영장.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/git-tturami/algorithm/aa61bdfa3d41f33dcf70c79ceb3c139a46fb6008/mose/1952-수영장.cpp -------------------------------------------------------------------------------- /mose/Solution_nogada.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() 9 | { 10 | int width; 11 | int height; 12 | int min1=0; 13 | int min_final=100; 14 | int B_cnt=0; 15 | int W_cnt=0; 16 | 17 | scanf("%d", &height); 18 | scanf("%d", &width); 19 | char chess[50][50]; 20 | 21 | for (int i = 0; i < height; i++) { 22 | for (int j = 0; j < width; j++) { 23 | //chess대입 24 | scanf(" %c", &chess[i][j]); 25 | } 26 | 27 | } 28 | 29 | //첫번째 B 30 | //두번째 W 31 | width = width - 7; 32 | height = height - 7; 33 | for (int i = 0; i < height; i++){ 34 | for( int j=0; j 4 | #include 5 | 6 | using namespace std; 7 | 8 | void function(int play_horse, int current_count, int temp_tot, int dice_abcd[][2]); 9 | int map_value(int play_horse, int dice_abcd[][2]); 10 | int map_plus_value(int play_horse, int number); 11 | void set_map_index(int play_horse, int number, int dice_abcd[][2]); 12 | void set_map_location(int play_horse, int number, int dice_abcd[][2]); 13 | void add_map_location(int play_horse, int number, int dice_abcd[][2]); 14 | int get_map_index(int play_horse, int dice_abcd[][2]); 15 | int get_map_location(int play_horse, int dice_abcd[][2]); 16 | int map_value(int play_horse, int dice_abcd[][2]); 17 | void check_algorithm(int play_horse, int dice_number, int dice_abcd[][2]); 18 | 19 | 20 | int final_tot = 0; 21 | int isFinish[4] = { 0, }; 22 | int dice_number[10] = { 0, }; 23 | 24 | //couunt, location(a,b,c,d)=0,1,2,3 25 | //25번째 : 1=9; 2=13; 3=19 40 :20번째는 0도 포함 26 | int map[5][22] = { {0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,35,36,38}, 27 | {10, 13, 16, 19}, {20, 22, 24}, { 30, 28, 27, 26}, {25, 30, 35, 40, 0} }; 28 | 29 | 30 | 31 | 32 | int map_value(int play_horse, int dice_abcd[][2]) { 33 | return map[dice_abcd[play_horse][1]][dice_abcd[play_horse][0]]; 34 | } 35 | int map_plus_value(int play_horse, int number) { 36 | return map[get_map_index(play_horse)][get_map_location(play_horse) + number]; 37 | } 38 | void set_map_index(int play_horse, int number, int dice_abcd[][2]) { 39 | dice_abcd[play_horse][1] = number; 40 | } 41 | void set_map_location(int play_horse, int number, int dice_abcd[][2]) { 42 | dice_abcd[play_horse][0] = number; 43 | } 44 | void add_map_location(int play_horse, int number, int dice_abcd[][2]) { 45 | dice_abcd[play_horse][0] += number; 46 | } 47 | 48 | int get_map_index(int play_horse, int dice_abcd[][2]) { 49 | return dice_abcd[play_horse][1]; 50 | } 51 | int get_map_location(int play_horse, int dice_abcd[][2]) { 52 | return dice_abcd[play_horse][0]; 53 | } 54 | 55 | int main() 56 | { 57 | int dice_abcd[5][2] = { -1, }; //0 = 맻번째 맵에서 몇번째 칸인지, 1 = 맵의 몇번째 것인지 , 마지막은 temp용 58 | for (int i = 0; i < 10; i++) { 59 | scanf("%d", &dice_number[i]); 60 | } 61 | 62 | function(0, 0, 0, dice_abcd); //horse_player(0~3), current_count(0~9),temp_tot(임시값), int dice_abcd[][2]; 63 | cout << final_tot << endl; 64 | cout << "Hello World!\n"; 65 | } 66 | 67 | void function(int play_horse, int current_count, int temp_tot, int dice_abcd[][2]) { 68 | 69 | if (current_count < 10) { 70 | 71 | for (int i = 0; i < 4; i++) { //같은 칸에있는 숫자가있는지 72 | if (play_horse != i) { 73 | 74 | //지금 현재 말이 '시작점'or '종료점'에 있지 않고, 나온 값을 더해 봤을 때 그자리에 말이 없어야함 75 | if (map_value(play_horse, dice_abcd) != 0) { 76 | check_algorithm(5, dice_number[current_count], dice_abcd); //temp 용에 나온 dice값을 더한다. 77 | if (map_value(5, dice_abcd) == map_value(i, dice_abcd)) { 78 | return; 79 | } 80 | } 81 | } 82 | } 83 | 84 | check_algorithm(play_horse, dice_number[current_count], dice_abcd); //나온 주사위 값을 현재의 노드값에 추가 1,2,3,4,5 85 | temp_tot += map_value(play_horse, dice_abcd); 86 | final_tot = max(temp_tot, final_tot); 87 | cout << "이번 주사위는 : " << dice_number[current_count] << "\t현재의 값은 : " << map_value(play_horse, dice_abcd) << "\t 누적값은 : " << temp_tot << endl; 88 | 89 | 90 | check_algorithm(play_horse, dice_number[current_count], dice_abcd); 91 | 92 | function(0, current_count + 1, temp_tot, dice_abcd); 93 | function(1, current_count + 1, temp_tot, dice_abcd); 94 | function(2, current_count + 1, temp_tot, dice_abcd); 95 | function(3, current_count + 1, temp_tot, dice_abcd); 96 | return; 97 | } 98 | else { 99 | printf("%d", final_tot); 100 | return; 101 | 102 | } 103 | 104 | } 105 | 106 | void check_algorithm(int play_horse, int dice_number, int dice_abcd[][2]) { 107 | // 10, 20, 30, 에 걸렸을때 맵의 index 이동 108 | 109 | if (map_plus_value(play_horse, dice_number) == 10) { 110 | set_map_index(play_horse, 1, dice_abcd); 111 | add_map_location(play_horse, dice_number - 5, dice_abcd); 112 | } 113 | else if (map_plus_value(play_horse, dice_number) == 20) { 114 | set_map_index(play_horse, 2, dice_abcd); 115 | add_map_location(play_horse, dice_number - 10, dice_abcd); 116 | } 117 | //TODO: 30이 2개임 118 | else if (map_plus_value(play_horse, dice_number) == 30 && get_map_index(play_horse, dice_abcd) == 0) { 119 | set_map_index(play_horse, 3, dice_abcd); 120 | add_map_location(play_horse, dice_number - 15, dice_abcd); 121 | } 122 | 123 | 124 | //현재 위치에 + 새로나온 주사위 수 가 마지막 인덱스를 넘어갈때 -> 25 이상으로 넘어갈때 125 | else if (get_map_location(play_horse, dice_abcd) + dice_number >= sizeof(map[get_map_index(play_horse, dice_abcd)]) / sizeof(int)) { 126 | if (get_map_index(play_horse, dice_abcd) == 1 || get_map_index(play_horse, dice_abcd) == 3) { 127 | set_map_index(play_horse, 4, dice_abcd); 128 | add_map_location(play_horse, dice_number - 4, dice_abcd); 129 | } 130 | else if (get_map_index(play_horse, dice_abcd) == 2) { 131 | set_map_index(play_horse, 4, dice_abcd); 132 | add_map_location(play_horse, dice_number - 3, dice_abcd); 133 | } 134 | // 40에 걸렸을때 135 | else if (get_map_index(play_horse, dice_abcd) == 0) { 136 | set_map_index(play_horse, 4, dice_abcd); 137 | add_map_location(play_horse, -17, dice_abcd); 138 | 139 | } 140 | } 141 | // 40에 이상 일때 0(종착점)으로 고정시키기 142 | if (get_map_index(play_horse, dice_abcd) == 4 && (get_map_location(play_horse, dice_abcd) > 3)) { 143 | set_map_location(play_horse, 4, dice_abcd); 144 | } 145 | } 146 | 147 | -------------------------------------------------------------------------------- /sangil/20190303/Intro.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/git-tturami/algorithm/aa61bdfa3d41f33dcf70c79ceb3c139a46fb6008/sangil/20190303/Intro.md -------------------------------------------------------------------------------- /sangil/Git-tturmi.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/git-tturami/algorithm/aa61bdfa3d41f33dcf70c79ceb3c139a46fb6008/sangil/Git-tturmi.md -------------------------------------------------------------------------------- /sangil/Readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/git-tturami/algorithm/aa61bdfa3d41f33dcf70c79ceb3c139a46fb6008/sangil/Readme.md -------------------------------------------------------------------------------- /seungjin/input.txt: -------------------------------------------------------------------------------- 1 | 10 13 2 | BBBBBBBBWBWBW 3 | BBBBBBBBBWBWB 4 | BBBBBBBBWBWBW 5 | BBBBBBBBBWBWB 6 | BBBBBBBBWBWBW 7 | BBBBBBBBBWBWB 8 | BBBBBBBBWBWBW 9 | BBBBBBBBBWBWB 10 | WWWWWWWWWWBWB 11 | WWWWWWWWWWBWB -------------------------------------------------------------------------------- /seungjin/redrawChessMap.py: -------------------------------------------------------------------------------- 1 | # f = open("input.txt", 'r') 2 | # line = f.readline() 3 | 4 | line = input() 5 | inputXY=line.split(" ") 6 | ylen = int(inputXY[0]) 7 | xlen = int(inputXY[1]) 8 | 9 | chessMap = [[0]*xlen for i in range(ylen)] 10 | 11 | for i in range (ylen): 12 | line = input() 13 | for j in range (xlen): 14 | chessMap[i][j]=line[j] 15 | 16 | # f.close() 17 | 18 | min = xlen * ylen 19 | 20 | for y in range (ylen-8+1): 21 | for x in range (xlen-8+1): 22 | #처음 black 23 | count =0 24 | for i in range (8): 25 | for j in range (8): 26 | nextOne="B" 27 | if((i+j)%2==0): 28 | nextOne="B" 29 | else: 30 | nextOne="W" 31 | if(chessMap[y+i][x+j]!=nextOne): 32 | count = count + 1 33 | 34 | 35 | if(min > count ): 36 | min = count 37 | 38 | #처음 white 39 | count =0 40 | for i in range (8): 41 | for j in range (8): 42 | nextOne="W" 43 | if((i+j)%2==0): 44 | nextOne="W" 45 | else: 46 | nextOne="B" 47 | if(chessMap[y+i][x+j]!=nextOne): 48 | count = count + 1 49 | 50 | if(min > count ): 51 | min = count 52 | 53 | 54 | print(min) 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /seungjin/redrawChessMapVer2.py: -------------------------------------------------------------------------------- 1 | # f = open("input.txt", 'r') 2 | # line = f.readline() 3 | 4 | line = input() 5 | inputXY=line.split(" ") 6 | ylen = int(inputXY[0]) 7 | xlen = int(inputXY[1]) 8 | 9 | chessMap = [[0]*xlen for i in range(ylen)] 10 | chessMap1 = [[0]*xlen for i in range(ylen)] 11 | # chessMap2 = [[0]*xlen for i in range(ylen)] 12 | 13 | 14 | 15 | for i in range (ylen): 16 | # line = f.readline() 17 | line = input() 18 | for j in range (xlen): 19 | chessMap[i][j]=line[j] 20 | 21 | # f.close() 22 | 23 | min = 32 24 | 25 | for y in range (ylen): 26 | for x in range (xlen): 27 | nextOne="B" 28 | if((y+x)%2==0): 29 | nextOne="B" 30 | else: 31 | nextOne="W" 32 | 33 | if(chessMap[y][x]!=nextOne): 34 | chessMap1[y][x]=1 35 | else: 36 | chessMap1[y][x]=0 37 | 38 | 39 | for y in range (ylen-8+1): 40 | for x in range (xlen-8+1): 41 | #처음 black 42 | count =0 43 | for i in range (8): 44 | for j in range (8): 45 | count = count + chessMap1[y+i][x+j] 46 | 47 | if(count > 64-count): 48 | count = 64-count 49 | if(min > count ): 50 | min = count 51 | 52 | # #처음 white 53 | # count =0 54 | # for i in range (8): 55 | # for j in range (8): 56 | # count = count + chessMap2[y+i][x+j] 57 | 58 | # if(min > count ): 59 | # min = count 60 | 61 | 62 | print(min) 63 | 64 | 65 | 66 | 67 | 68 | --------------------------------------------------------------------------------