diff --git a/BOJ-ios/README.md b/BOJ-ios/README.md index b9e88ce..2f8877f 100644 --- a/BOJ-ios/README.md +++ b/BOJ-ios/README.md @@ -7,4 +7,4 @@ | 3차시 | 2024.03.26 | 펜윅트리 | [구간 합 구하기](https://www.acmicpc.net/problem/2042) | [#13](https://github.com/AlgoLeadMe/AlgoLeadMe-9/pulls/13) | | 4차시 | 2024.03.30 | 볼록껍질 | [볼록 껍질](https://www.acmicpc.net/problem/1708) | [#14](https://github.com/AlgoLeadMe/AlgoLeadMe-9/pulls/14) | | 5차시 | 2024.04.29 | 스위핑 | [여러 직사각형의 전체 면적 구하기](https://www.acmicpc.net/problem/2672) | [#19](https://github.com/AlgoLeadMe/AlgoLeadMe-9/pulls/19) | -| 6차시 | 2024.05.13 | 위상정렬 | [줄 세우기](https://www.acmicpc.net/problem/2252) | [#20](https://github.com/AlgoLeadMe/AlgoLeadMe-9/pulls/20) | +| 6차시 | 2024.05.13 | 위상정렬 | [줄 세우기](https://www.acmicpc.net/problem/2252) | [#20](https://github.com/AlgoLeadMe/AlgoLeadMe-9/pulls/20) | \ No newline at end of file diff --git "a/BOJ-ios/\354\212\244\354\234\204\355\225\221/P2672\353\262\210_\354\227\254\353\237\254_\354\247\201\354\202\254\352\260\201\355\230\225\354\235\230_\354\240\204\354\262\264_\353\251\264\354\240\201_\352\265\254\355\225\230\352\270\260/Main.java" "b/BOJ-ios/\354\212\244\354\234\204\355\225\221/P2672\353\262\210_\354\227\254\353\237\254_\354\247\201\354\202\254\352\260\201\355\230\225\354\235\230_\354\240\204\354\262\264_\353\251\264\354\240\201_\352\265\254\355\225\230\352\270\260/Main.java" new file mode 100644 index 0000000..2fa31c0 --- /dev/null +++ "b/BOJ-ios/\354\212\244\354\234\204\355\225\221/P2672\353\262\210_\354\227\254\353\237\254_\354\247\201\354\202\254\352\260\201\355\230\225\354\235\230_\354\240\204\354\262\264_\353\251\264\354\240\201_\352\265\254\355\225\230\352\270\260/Main.java" @@ -0,0 +1,84 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.StringTokenizer; + +public class Main { + static class RectangleEvent implements Comparable { + int x; + int yUp; + int yDown; + int chk; + + public RectangleEvent(int x, int yDown, int yUp, int chk) { + this.x = x; + this.yUp = yUp; + this.yDown = yDown; + this.chk = chk; + } + + @Override + public int compareTo(RectangleEvent o) { + if (this.x == o.x) + return this.chk - o.chk; + return this.x - o.x; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null || getClass() != obj.getClass()) { + return false; + } + RectangleEvent that = (RectangleEvent) obj; + return this.x == that.x && this.yUp == that.yUp && this.yDown == that.yDown && this.chk == that.chk; + } + + @Override + public int hashCode() { + return Objects.hash(x, yUp, yDown, chk); + } + } + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = null; + int n = Integer.parseInt(br.readLine()); + List events = new ArrayList<>(); + int[] sweep = new int[20001]; + while (n-- > 0) { + st = new StringTokenizer(br.readLine()); + int xStart = (int) (Double.parseDouble(st.nextToken()) * 10); + int yDown = (int) (Double.parseDouble(st.nextToken()) * 10); + int xEnd = xStart + (int) (Double.parseDouble(st.nextToken()) * 10); + int height = (int) (Double.parseDouble(st.nextToken()) * 10); + int yUp = yDown + height; + events.add(new RectangleEvent(xStart, yDown, yUp, 1)); + events.add(new RectangleEvent(xEnd, yDown, yUp, -1)); + } + Collections.sort(events); + int area = 0; + int x = 0; + for (RectangleEvent event : events) { + int count = 0; + for (int i = 0; i < 20001; i++) + if (sweep[i] > 0) + count++; + area += count * (event.x - x); + for (int i = event.yDown; i < event.yUp; i++) { + if (event.chk == 1) + sweep[i]++; + else + sweep[i]--; + } + x = event.x; + } + System.out.println(area % 100 == 0 ? (int) (area * 0.01) : String.format("%.2f", area * 0.01)); + } +} diff --git a/SunYerim/README.md b/SunYerim/README.md index e7536aa..617a30e 100644 --- a/SunYerim/README.md +++ b/SunYerim/README.md @@ -1,7 +1,8 @@ ## ✏️ 기록 -| 차시 | 날짜 | 문제유형 | 링크 | 풀이 | -|:---:|:----------:|:----:|:-----------------------------------------------:|:--------------------------------------------------------:| +| 차시 | 날짜 | 문제유형 | 링크 | 풀이 | +|:---:|:----------:|:----:|:---------------------------------------------------:|:--------------------------------------------------------:| | 1차시 | 2024.03.18 | 구현 | [이차원 배열과 연산](https://www.acmicpc.net/problem/17140) | [#1](https://github.com/AlgoLeadMe/AlgoLeadMe-9/pull/5) | -| 2차시 | 2024.03.22 | 스택 | [키로거](https://www.acmicpc.net/problem/5397) | [#2](https://github.com/AlgoLeadMe/AlgoLeadMe-9/pull/7) | -| 3차시 | 2024.03.26 | DP | [앱](https://www.acmicpc.net/problem/7579) | [#3](https://github.com/AlgoLeadMe/AlgoLeadMe-9/pull/11) | +| 2차시 | 2024.03.22 | 스택 | [키로거](https://www.acmicpc.net/problem/5397) | [#2](https://github.com/AlgoLeadMe/AlgoLeadMe-9/pull/7) | +| 3차시 | 2024.03.26 | DP | [앱](https://www.acmicpc.net/problem/7579) | [#3](https://github.com/AlgoLeadMe/AlgoLeadMe-9/pull/11) | +| 4차시 | 2024.03.30 | 그래프 | [탈출](https://www.acmicpc.net/problem/3055) | [#4](https://github.com/AlgoLeadMe/AlgoLeadMe-9/pull/16) | \ No newline at end of file diff --git "a/SunYerim/\352\267\270\353\236\230\355\224\204/BOJ3055.java" "b/SunYerim/\352\267\270\353\236\230\355\224\204/BOJ3055.java" new file mode 100644 index 0000000..e132a68 --- /dev/null +++ "b/SunYerim/\352\267\270\353\236\230\355\224\204/BOJ3055.java" @@ -0,0 +1,123 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Queue; +import java.util.StringTokenizer; + +public class BOJ3055 { + static int r, c; + static int startX, startY, endX, endY; + static char[][] map; + static boolean[][] visited; + static boolean[][] waterVisited; + static int[] dx = {1, -1, 0, 0}; + static int[] dy = {0, 0, -1, 1}; + static ArrayDeque water; + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + r = Integer.parseInt(st.nextToken()); + c = Integer.parseInt(st.nextToken()); + map = new char[r][c]; + visited = new boolean[r][c]; + waterVisited = new boolean[r][c]; + water = new ArrayDeque(); + + for (int i = 0; i < r; i++) { + String tmp = br.readLine(); + for (int j = 0; j < c; j++) { + map[i][j] = tmp.charAt(j); + if (map[i][j] == 'S') { + startX = i; + startY = j; + } else if (map[i][j] == 'D') { + endX = i; + endY = j; + } else if (map[i][j] == '*') { + water.add(new Node(i, j, 0)); + } + } + } + + bfs(startX, startY); + } + + private static void bfs(int x, int y) { + Queue queue = new ArrayDeque<>(); // 두더지가 가는 경로만 담는다 + queue.add(new Node(x, y, 0)); // 출발지점 넣고 + visited[x][y] = true; + + while (!queue.isEmpty()) { + // 물을 퍼뜨린 후 고슴도치 이동 -> 고슴도치도 물은 통과 못한다. + int size = queue.size(); + for (int s = 0; s < size; s++) { + Node curr = queue.poll(); + int currX = curr.x; + int currY = curr.y; + int currCnt = curr.count; + if (map[currX][currY] == '*') + continue; + + // 기저 + if (map[currX][currY] == 'D') { + System.out.println(currCnt); + return; + } + for (int i = 0; i < 4; i++) { + int nx = dx[i] + currX; + int ny = dy[i] + currY; + if (nx >= 0 && ny >= 0 && nx < r && ny < c && !visited[nx][ny]) { + // 고슴도치가 가려는 자리에 물이나 돌이 있으면 + if (map[nx][ny] == '*' || map[nx][ny] == 'X') continue; + visited[nx][ny] = true; + + queue.add(new Node(nx, ny, currCnt+1)); + + } + } + + } + // 우선 물부터 퍼뜨린다. -> 물은 돌과 소굴이 있는 자리, D로는 퍼질 수 없다. + int waterSize = water.size(); + for (int i = 0; i < waterSize; i++) { + Node waters = water.poll(); + int waterX = waters.x; + int waterY = waters.y; + //int waterCnt = waters.count; + // 가려는 곳이 돌이 아니고 비버의 굴이 아닐때 + for (int j = 0; j < 4; j++) { + int nx = dx[j] + waterX; + int ny = dy[j] + waterY; + if (nx >= 0 && ny >= 0 && nx < r && ny < c) { + // 돌이아니고 굴이 아니여야함 + if (map[nx][ny] == 'X' || map[nx][ny] == 'D' || waterVisited[nx][ny]) continue; + // 갈 수 있는 곳이라면 + + map[nx][ny] = '*'; + waterVisited[nx][ny] = true; + water.add(new Node(nx, ny, 0)); + + + } + } + } + } + + System.out.println("KAKTUS"); + + + + + } + + static class Node { + private int x, y, count; + public Node (int x, int y, int count) { + this.x = x; + this.y = y; + this.count = count; + } + } +} \ No newline at end of file diff --git "a/erase-jeong/BFS/BOJ2178_\353\257\270\353\241\234\355\203\220\354\203\211.py" "b/erase-jeong/BFS/BOJ2178_\353\257\270\353\241\234\355\203\220\354\203\211.py" new file mode 100644 index 0000000..a3c4539 --- /dev/null +++ "b/erase-jeong/BFS/BOJ2178_\353\257\270\353\241\234\355\203\220\354\203\211.py" @@ -0,0 +1,38 @@ +from collections import deque + +N, M = map(int, input().split()) + +graph = [] + +for _ in range(N): + graph.append(list(map(int, input()))) + +def BFS(x, y): + # 이동할 상, 하, 좌, 우 방향 정의 + dx = [-1,1,0,0] + dy = [0,0,-1,1] + + queue = deque() + queue.append((x,y)) + + while queue: + x, y = queue.popleft() + + for i in range(4): + nx = x + dx[i] + ny = y + dy[i] + + if nx<0 or nx>=N or ny<0 or ny>=M: + continue + + if graph[nx][ny]==0: + continue + + if graph[nx][ny]==1: + graph[nx][ny] = graph[x][y]+1 + queue.append((nx,ny)) + + + return graph[N-1][M-1] + +print(BFS(0,0)) \ No newline at end of file diff --git "a/erase-jeong/DFS_BFS/\354\264\214\354\210\230\352\263\204\354\202\260.py" "b/erase-jeong/DFS_BFS/\354\264\214\354\210\230\352\263\204\354\202\260.py" new file mode 100644 index 0000000..790e928 --- /dev/null +++ "b/erase-jeong/DFS_BFS/\354\264\214\354\210\230\352\263\204\354\202\260.py" @@ -0,0 +1,35 @@ +#입력값 받는 부분 +n=int(input()) +a,b=map(int,input().split()) +m=int(input()) + +#기본 선언 +graph=[[] for _ in range(n+1)] #노드의 번호와 배열 번호 통일시키기 위해서 n이 아닌 n+1 사용 +visited=[[False]*(n+1)] +result=[] + + +for _ in range(m): + x,y=map(int, input().split()) + graph[x].append(y) + graph[y].append(x) + + + +def dfs(v,num): + num+=1 + visited[v]=True + + if v==b: + result.append(num) + + for i in graph[v]: + if not visited[i]: + dfs(i,num) + +dfs(a,0) + +if len(result)==0: + print(-1) +else: + print(result) diff --git a/erase-jeong/README.md b/erase-jeong/README.md index e62f31d..aa29d04 100644 --- a/erase-jeong/README.md +++ b/erase-jeong/README.md @@ -2,5 +2,7 @@ | 차시 | 날짜 | 문제유형 | 링크 | 풀이 | |:----:|:---------:|:----:|:-----:|:----:| -| 1차시 | 2024.03.18 | 그리디 | [구명보트](https://school.programmers.co.kr/learn/courses/30/lessons/42885) | [#1](https://github.com/AlgoLeadMe/AlgoLeadMe-9/pull/4) | ---- +| 1차시 | 2023.03.18 | 그리디 | [구명보트](https://school.programmers.co.kr/learn/courses/30/lessons/42885) | [#1](https://github.com/AlgoLeadMe/AlgoLeadMe-9/pull/4)| +| 2차시 | 2023.03.23 | DFS/BFS | [촌수계산](https://www.acmicpc.net/problem/2644) | [#2](https://github.com/AlgoLeadMe/AlgoLeadMe-9/pull/8)| +| 3차시 | 2023.03.28 | DP | [평범한 배낭](https://www.acmicpc.net/problem/12865) | [#3](https://github.com/AlgoLeadMe/AlgoLeadMe-9/pull/12)| +| 4차시 | 2023.03.28 | DP | [미로 탐색](https://www.acmicpc.net/problem/2178) | [#4](https://github.com/AlgoLeadMe/AlgoLeadMe-9/pull/17)| diff --git a/wjdheesp44/README.md b/wjdheesp44/README.md index 27e1e64..2f91b38 100644 --- a/wjdheesp44/README.md +++ b/wjdheesp44/README.md @@ -5,4 +5,5 @@ | 1차시 | 2024.03.18 | 구현 | [주사위 굴리기](https://www.acmicpc.net/problem/14499) | [#3](https://github.com/AlgoLeadMe/AlgoLeadMe-9/pull/3) | | 2차시 | 2024.03.22 | 구현 | [뱀](https://www.acmicpc.net/problem/3190) | [#6](https://github.com/AlgoLeadMe/AlgoLeadMe-9/pull/6) | | 3차시 | 2024.03.26 | 백트래킹 | [연산자 끼워넣기](https://www.acmicpc.net/problem/14888) | [#10](https://github.com/AlgoLeadMe/AlgoLeadMe-9/pull/10) | +| 4차시 | 2024.03.30 | bfs | [안전 영역](https://www.acmicpc.net/problem/2468) | [#15](https://github.com/AlgoLeadMe/AlgoLeadMe-9/pull/15) | --- diff --git "a/wjdheesp44/bfs/2468_\354\225\210\354\240\204 \354\230\201\354\227\255.py" "b/wjdheesp44/bfs/2468_\354\225\210\354\240\204 \354\230\201\354\227\255.py" new file mode 100644 index 0000000..3cb468f --- /dev/null +++ "b/wjdheesp44/bfs/2468_\354\225\210\354\240\204 \354\230\201\354\227\255.py" @@ -0,0 +1,38 @@ +import sys +from collections import deque +input = sys.stdin.readline + +sum = 0 +cnt = 0 +n = int(input()) +max_height = 0 +board = [list(map(int, input().split())) for _ in range(n)] + +max_height = max(map(max, board)) + +def bfs(x, y, k): + dx, dy = [-1, 0, 1, 0], [0, 1, 0, -1] + q = deque() + q.append((x, y)) + + while q: + x, y = q.popleft() + for i in range(4): + nx, ny = x + dx[i], y + dy[i] + if 0 <= nx < n and 0 <= ny < n and visited[nx][ny] == 0 and board[nx][ny] > k: + visited[nx][ny] = 1 + q.append((nx, ny)) + + +for k in range(max_height): + visited = [[0] * n for _ in range(n)] + cnt = 0 + + for i in range(n): + for j in range(n): + if visited[i][j] == 0 and board[i][j] > k: + bfs(i, j, k) + cnt += 1 + sum = max(sum, cnt) + +print(sum) \ No newline at end of file