Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5-kangrae-jo #18

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified kangrae-jo/.DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions kangrae-jo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
76 changes: 76 additions & 0 deletions kangrae-jo/BFS/4-kangrae-jo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include <queue>
#include <string>
#include <vector>

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<pair<int, int>> 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<vector<int>> 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;
}
51 changes: 51 additions & 0 deletions kangrae-jo/DP/5-kangrae-jo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include <iostream>
#include <algorithm>

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<N; i++){
cin >> 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;
}
3 changes: 3 additions & 0 deletions kangrae-jo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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|

---