diff --git a/kangrae-jo/.DS_Store b/kangrae-jo/.DS_Store index cffb731..c024126 100644 Binary files a/kangrae-jo/.DS_Store and b/kangrae-jo/.DS_Store differ diff --git a/kangrae-jo/.gitignore b/kangrae-jo/.gitignore new file mode 100644 index 0000000..e43b0f9 --- /dev/null +++ b/kangrae-jo/.gitignore @@ -0,0 +1 @@ +.DS_Store diff --git a/kangrae-jo/BFS/4-kangrae-jo.cpp b/kangrae-jo/BFS/4-kangrae-jo.cpp new file mode 100644 index 0000000..391173e --- /dev/null +++ b/kangrae-jo/BFS/4-kangrae-jo.cpp @@ -0,0 +1,76 @@ +#include +#include +#include + +using namespace std; + +#define EMPTY 0 +#define PATH 1 +#define WALL 2 +#define VISITED 3 + +int offset[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; +int board[102][102] = {EMPTY,}; + +queue> q; + +bool check(int cX, int cY, int itemX, int itemY) { + if (cX == itemX && cY == itemY) return true; + else return false; +} +bool isMoveable(int cX_, int cY_) { + if (cX_ < 0 || cX_ > 100 || cY_ < 0 || cY_ > 100) return false; + if (board[cY_][cX_] == PATH) return true; + else return false; +} +int move(int cX, int cY, int dir) { + int cY_ = cY + offset[dir][0]; + int cX_ = cX + offset[dir][1]; + + if (isMoveable(cX_, cY_)) q.push(make_pair(cY_, cX_)); + + return 0; +} + +int solution(vector> rectangle, int characterX, int characterY, int itemX, int itemY) { + int answer = 0; + + // init + for (auto& i : rectangle) { + int x1 = i[0]*2, x2 = i[2]*2; + int y1 = i[1]*2, y2 = i[3]*2; + for (int y = y1; y <= y2; y++) { + for (int x = x1; x <= x2; x++) { + if (board[y][x] == WALL) continue; + else if (y == y1 || y == y2 || x == x1 || x == x2) board[y][x] = PATH; + else board[y][x] = WALL; + } + } + } + characterX *= 2; + characterY *= 2; + itemX *= 2; + itemY *= 2; + + // BFS + q.push(make_pair(characterY, characterX)); + + while (!q.empty()) { + int size = q.size(); + + while (size--){ + int cY = q.front().first; + int cX = q.front().second; + + board[cY][cX] = VISITED; + q.pop(); + + if (check(cX, cY, itemX, itemY)) return answer / 2; + + for (int dir = 0; dir < 4; dir++) move(cX, cY, dir); + } + answer++; + } + + return answer / 2; +} \ No newline at end of file diff --git a/kangrae-jo/DP/5-kangrae-jo.cpp b/kangrae-jo/DP/5-kangrae-jo.cpp new file mode 100644 index 0000000..95fda12 --- /dev/null +++ b/kangrae-jo/DP/5-kangrae-jo.cpp @@ -0,0 +1,51 @@ +#include +#include + +using namespace std; + +int field[1001][1001]; +int maxX=0, maxY=0; +int minX=1001, minY=1001; + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + int N, K; + cin >> N >> K; + + int x1,y1,x2,y2; + + for (int i=0; i> x1 >> y1 >> x2 >> y2; + + + minX=min(minX,x1); + minY=min(minY,y1); + maxX=max(maxX,x2); + maxY=max(maxY,y2); + + field[y1][x1] += 1; + field[y1][x2] -= 1; + field[y2][x1] -= 1; + field[y2][x2] += 1; + } + + for(int y=minY; y<=maxY; y++) + for (int x=minX; x<=maxX; x++) + field[y][x+1] += field[y][x]; + + for (int x=minX; x<=maxX; x++) + for(int y=minY; y<=maxY; y++) + field[y+1][x] += field[y][x]; + + int result = 0; + for(int y=minY; y<=maxY; y++) + for (int x=minX; x<=maxX; x++) + if (field[y][x] == K) result++; + + cout << result; + + return 0; +} \ No newline at end of file diff --git a/kangrae-jo/README.md b/kangrae-jo/README.md index 16c0ace..f77ffdf 100644 --- a/kangrae-jo/README.md +++ b/kangrae-jo/README.md @@ -3,4 +3,7 @@ | 차시 | 날짜 | 문제유형 | 링크 | 풀이 | |:----:|:---------:|:----:|:-----:|:----:| | 1차시 | 2024.09.28 | DP | [연속합](https://www.acmicpc.net/problem/1912)|[#2]https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/2| +| 4차시 | 2024.10.05 | BFS | [아이템 줍기](https://school.programmers.co.kr/learn/courses/30/lessons/87694)|[#12]https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/12| +| 5차시 | 2024.11.02 | DP | [경쟁 배타의 원리](https://level.goorm.io/exam/162070/%EA%B2%BD%EC%9F%81-%EB%B0%B0%ED%83%80%EC%9D%98-%EC%9B%90%EB%A6%AC/quiz/1)|[#18]https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/18| + ---