Skip to content

Commit

Permalink
Merge branch 'main' into 24-yuyu0830
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyu0830 authored Sep 2, 2024
2 parents 63d2e57 + 617e119 commit ed7d392
Show file tree
Hide file tree
Showing 8 changed files with 285 additions and 18 deletions.
66 changes: 66 additions & 0 deletions InSange/BFS/310_Minimum Height Trees.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#include <vector>
#include <map>
#include <queue>

using namespace std;

class Solution {
public:
vector<int> findMinHeightTrees(int n, vector<vector<int>>& edges) {
map<int, vector<int>> m;
vector<int> ans;
vector<bool> check(n, false);
int* degree = new int[n] {0};

for (vector<int> node : edges)
{
m[node[0]].push_back(node[1]);
m[node[1]].push_back(node[0]);
degree[node[0]]++;
degree[node[1]]++;
}
int current_n = n;

queue<int> q;
if (current_n > 2)
{
for (int i = 0; i < n; i++)
{
if (degree[i] == 1 && check[i] == false)
{
check[i] = true;
q.push(i);
current_n--;
}
}
}
while (current_n > 2 && !q.empty())
{
int size = q.size();

for (int j = 0; j < size; j++)
{
int remove_n = q.front();
q.pop();

for (auto node : m[remove_n])
{
degree[node]--;
if (degree[node] == 1)
{
q.push(node);
check[node] = true;
current_n--;
}
}
}
}

for (int i = 0; i < n; i++)
{
if (check[i] == false) ans.push_back(i);
}

return ans;
}
};
2 changes: 2 additions & 0 deletions InSange/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
| 22์ฐจ์‹œ | 2024.07.31 | DP | [Filling Bookcase Shelves](https://leetcode.com/problems/filling-bookcase-shelves/) | [#22](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/81)]
| 23์ฐจ์‹œ | 2024.08.03 | ์Šฌ๋ผ์ด๋”ฉ ์œˆ๋„์šฐ | [Minimum Swaps to Group All 1's Together 2](https://leetcode.com/problems/minimum-swaps-to-group-all-1s-together-ii/) | [#23](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/82)]
| 24์ฐจ์‹œ | 2024.08.04 | BFS | [ํŠธ๋ฆฌ](https://www.acmicpc.net/problem/1068) | [#24](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/83)]
| 25์ฐจ์‹œ | 2024.08.10 | BFS | [Minimum Height Trees](https://leetcode.com/problems/minimum-height-trees/) | [#25](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/87)]
| 26์ฐจ์‹œ | 2024.08.11 | ์ˆ˜ํ•™ | [Magic Squares In Grid](https://leetcode.com/problems/magic-squares-in-grid/) | [#26](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/89)]
---

https://leetcode.com/problems/robot-collisions/
55 changes: 55 additions & 0 deletions InSange/์ˆ˜ํ•™/840_Magic Squares In Grid.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include <vector>

using namespace std;

class Solution {
public:
bool Check(int r, int c, vector<vector<int>>& grid)
{
vector<bool> isCheck(10, false);

for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
int num = grid[r + i][c + j];
if (num < 1 || num > 9) return false;
if (isCheck[num]) return false;
isCheck[num] = true;
}
}

int standard_num = grid[r][c] + grid[r + 1][c + 1] + grid[r + 2][c + 2];
if (standard_num != grid[r][c + 2] + grid[r + 1][c + 1] + grid[r + 2][c]) return false;

for (int i = 0; i < 3; i++)
{
if (standard_num != (grid[r + i][c] + grid[r + i][c + 1] + grid[r + i][c + 2])) return false;
}

for (int i = 0; i < 3; i++)
{
if (standard_num != (grid[r][c + i] + grid[r + 1][c + i] + grid[r + 2][c + i])) return false;
}

return true;
}

int numMagicSquaresInside(vector<vector<int>>& grid) {
int col = grid[0].size(), row = grid.size();

if (col < 3 || row < 3) return 0;

int ans = 0;

for (int i = 0; i < row - 2; i++)
{
for (int j = 0; j < col - 2; j++)
{
if (Check(i, j, grid)) ans++;
}
}

return ans;
}
};
44 changes: 26 additions & 18 deletions seongwon030/README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
## โœ๏ธ ๊ธฐ๋ก

| ์ฐจ์‹œ | ๋‚ ์งœ | ๋ฌธ์ œ์œ ํ˜• | ๋งํฌ | ํ’€์ด |
| :----: | :--------: | :--------: | :-----------------------------------------------------: | :-------------------------------------------------------: |
| 1์ฐจ์‹œ | 2024.03.11 | ์Šคํƒ | [์‡ ๋ง‰๋Œ€๊ธฐ](https://www.acmicpc.net/problem/10799) | [#1](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/2) |
| 2์ฐจ์‹œ | 2024.03.16 | BFS | [ํ† ๋งˆํ† ](https://www.acmicpc.net/problem/7576) | [#2](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/7) |
| 3์ฐจ์‹œ | 2024.03.19 | BFS | [3์ฐจ์›ํ† ๋งˆํ† ](https://www.acmicpc.net/problem/7569) | [#3](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/11) |
| 4์ฐจ์‹œ | 2024.03.25 | BFS | [์ˆจ๋ฐ”๊ผญ์งˆ3](https://www.acmicpc.net/problem/13549) | [#4](https://github.com/AlgoLeadMe/AlgoLeadMe8/pull/16) |
| 5์ฐจ์‹œ | 2024.03.30 | BFS | [์ ํ”„์ ํ”„](https://www.acmicpc.net/problem/11060) | [#5](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/23) |
| 6์ฐจ์‹œ | 2024.04.02 | ์Šคํƒ | [๋ฌธ์ž์—ดํญ๋ฐœ](https://www.acmicpc.net/problem/9935) | [#6](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/25) |
| 7์ฐจ์‹œ | 2024.04.05 | ์Šคํƒ | [์˜คํฐ์ˆ˜](https://www.acmicpc.net/problem/17298) | [#7](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/30) |
| 8์ฐจ์‹œ | 2024.04.12 | BFS | [๊ฒฐํ˜ผ์‹](https://www.acmicpc.net/problem/5567) | [#8](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/37) |
| 9์ฐจ์‹œ | 2024.04.29 | DP | [1,2,3 ๋”ํ•˜๊ธฐ 3](https://www.acmicpc.net/problem/15988) | [#9](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/38) |
| 10์ฐจ์‹œ | 2024.05.07 | ์ˆ˜ํ•™ | [์—ฐ์† ํ•ฉ](https://www.acmicpc.net/problem/2737) | [#10](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/43) |
| 11์ฐจ์‹œ | 2024.05.07 | DP | [ํ•ฉ๋ถ„ํ•ด](https://www.acmicpc.net/problem/2225) | [#11](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/44) |
| 12์ฐจ์‹œ | 2024.05.13 | ๋ธŒ๋ฃจํŠธํฌ์Šค | [์•”ํ˜ธ๋งŒ๋“ค๊ธฐ](https://www.acmicpc.net/problem/1759) | [#12](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/50) |
| 13์ฐจ์‹œ | 2024.05.23 | ๋ถ„ํ• ์ •๋ณต | [ํ”ผ๋ณด๋‚˜์น˜ ์ˆ˜ 6](https://www.acmicpc.net/problem/11444) | [#13](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/55) |
| 14์ฐจ์‹œ | 2024.05.28 | ํ | [๊ฐ€์šด๋ฐ๋ฅผ ๋งํ•ด์š”](https://www.acmicpc.net/problem/1655) | [#14](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/58) |
| 15์ฐจ์‹œ | 2024.06.01 | ํ | [์ค‘์•™๊ฐ’ ๊ตฌํ•˜๊ธฐ](https://www.acmicpc.net/problem/2696) | [#15](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/61) |
| 16์ฐจ์‹œ | 2024.07.04 | DP | [์—ฐ์†ํ•ฉ](https://www.acmicpc.net/problem/1912) | [#16](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/66) |
| ์ฐจ์‹œ | ๋‚ ์งœ | ๋ฌธ์ œ์œ ํ˜• | ๋งํฌ | ํ’€์ด |
| :----: | :--------: | :------------: | :-----------------------------------------------------: | :-------------------------------------------------------: |
| 1์ฐจ์‹œ | 2024.03.11 | ์Šคํƒ | [์‡ ๋ง‰๋Œ€๊ธฐ](https://www.acmicpc.net/problem/10799) | [#1](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/2) |
| 2์ฐจ์‹œ | 2024.03.16 | BFS | [ํ† ๋งˆํ† ](https://www.acmicpc.net/problem/7576) | [#2](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/7) |
| 3์ฐจ์‹œ | 2024.03.19 | BFS | [3์ฐจ์›ํ† ๋งˆํ† ](https://www.acmicpc.net/problem/7569) | [#3](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/11) |
| 4์ฐจ์‹œ | 2024.03.25 | BFS | [์ˆจ๋ฐ”๊ผญ์งˆ3](https://www.acmicpc.net/problem/13549) | [#4](https://github.com/AlgoLeadMe/AlgoLeadMe8/pull/16) |
| 5์ฐจ์‹œ | 2024.03.30 | BFS | [์ ํ”„์ ํ”„](https://www.acmicpc.net/problem/11060) | [#5](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/23) |
| 6์ฐจ์‹œ | 2024.04.02 | ์Šคํƒ | [๋ฌธ์ž์—ดํญ๋ฐœ](https://www.acmicpc.net/problem/9935) | [#6](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/25) |
| 7์ฐจ์‹œ | 2024.04.05 | ์Šคํƒ | [์˜คํฐ์ˆ˜](https://www.acmicpc.net/problem/17298) | [#7](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/30) |
| 8์ฐจ์‹œ | 2024.04.12 | BFS | [๊ฒฐํ˜ผ์‹](https://www.acmicpc.net/problem/5567) | [#8](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/37) |
| 9์ฐจ์‹œ | 2024.04.29 | DP | [1,2,3 ๋”ํ•˜๊ธฐ 3](https://www.acmicpc.net/problem/15988) | [#9](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/38) |
| 10์ฐจ์‹œ | 2024.05.07 | ์ˆ˜ํ•™ | [์—ฐ์† ํ•ฉ](https://www.acmicpc.net/problem/2737) | [#10](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/43) |
| 11์ฐจ์‹œ | 2024.05.07 | DP | [ํ•ฉ๋ถ„ํ•ด](https://www.acmicpc.net/problem/2225) | [#11](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/44) |
| 12์ฐจ์‹œ | 2024.05.13 | ๋ธŒ๋ฃจํŠธํฌ์Šค | [์•”ํ˜ธ๋งŒ๋“ค๊ธฐ](https://www.acmicpc.net/problem/1759) | [#12](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/50) |
| 13์ฐจ์‹œ | 2024.05.23 | ๋ถ„ํ• ์ •๋ณต | [ํ”ผ๋ณด๋‚˜์น˜ ์ˆ˜ 6](https://www.acmicpc.net/problem/11444) | [#13](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/55) |
| 14์ฐจ์‹œ | 2024.05.28 | ํ | [๊ฐ€์šด๋ฐ๋ฅผ ๋งํ•ด์š”](https://www.acmicpc.net/problem/1655) | [#14](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/58) |
| 15์ฐจ์‹œ | 2024.06.01 | ํ | [์ค‘์•™๊ฐ’ ๊ตฌํ•˜๊ธฐ](https://www.acmicpc.net/problem/2696) | [#15](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/61) |
| 16์ฐจ์‹œ | 2024.07.04 | DP | [์—ฐ์†ํ•ฉ](https://www.acmicpc.net/problem/1912) | [#16](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/66) |
| 17์ฐจ์‹œ | 2024.07.05 | ์ตœ์†Œ์ŠคํŒจ๋‹ํŠธ๋ฆฌ | [์ตœ์†Œ์ŠคํŒจ๋‹ํŠธ๋ฆฌ](https://www.acmicpc.net/problem/1197) | [#17](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/67) |
| 18์ฐจ์‹œ | 2024.07.08 | ์ตœ์†Œ์ŠคํŒจ๋‹ํŠธ๋ฆฌ | [์ •๋ณต์ž](https://www.acmicpc.net/problem/14950) | [#18](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/69) |
| 19์ฐจ์‹œ | 2024.07.14 | ์ตœ์†Œ์ŠคํŒจ๋‹ํŠธ๋ฆฌ | [์ „๋ ฅ๋‚œ](https://www.acmicpc.net/problem/6497) | [#19](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/73) |
| 20์ฐจ์‹œ | 2024.07.22 | ์œ ๋‹ˆ์˜จํŒŒ์ธ๋“œ | [์ง‘ํ•ฉ์˜ํ‘œํ˜„ ](https://www.acmicpc.net/problem/1717) | [#20](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/76) |
| 21์ฐจ์‹œ | 2024.07.24 | DFS | [ํŠธ๋ฆฌ](https://www.acmicpc.net/problem/1068) | [#21](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/78) |
| 22์ฐจ์‹œ | 2024.07.30 | DFS | [์•ŒํŒŒ๋ฒณ](https://www.acmicpc.net/problem/1987) | [#22](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/80) |
| 23์ฐจ์‹œ | 2024.08.05 | DFS | [๊ฒŒ์ž„](https://www.acmicpc.net/problem/1103) | [#23](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/85) |
| 24์ฐจ์‹œ | 2024.08.10 | ๊ตฌํ˜„ | [์ฃผ์‚ฌ์œ„๊ตด๋ฆฌ๊ธฐ](https://www.acmicpc.net/problem/14499) | [#24](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/66) |

---
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import sys
input = sys.stdin.readline

n,m,x,y,k = map(int,input().split())
arr = []
for _ in range(n):
arr.append(list(map(int,input().split())))

move = list(map(int,input().split()))

# ์ฃผ์‚ฌ์œ„ (์„œ,๋ถ,์œ—๋ฉด,์˜ค,๋‚จ,์•„๋žซ๋ฉด) ์ดˆ๊ธฐ๊ฐ’
dice = [0]*6
# k=1, ๋™์ชฝ์œผ๋กœ ์ด๋™
# k=2, ์„œ์ชฝ์œผ๋กœ ์ด๋™
# k=3, ๋ถ์ชฝ์œผ๋กœ ์ด๋™
# k=4, ๋‚จ์ชฝ์œผ๋กœ ์ด๋™

for i in move:
if i == 1: # ๋™
if y+1 < m:
y+=1
dice[0],dice[2],dice[3],dice[5] = dice[5],dice[0],dice[2],dice[3]
print(dice[2])
if arr[x][y] == 0:
arr[x][y] = dice[5]
else:
dice[5] = arr[x][y]
arr[x][y] = 0
elif i == 2: # ์„œ
if y-1 >=0:
y-=1
dice[0],dice[2],dice[3],dice[5] = dice[2],dice[3],dice[5],dice[0]
print(dice[2])
if arr[x][y] == 0:
arr[x][y] = dice[5]
else:
dice[5] = arr[x][y]
arr[x][y] = 0
elif i == 3: # ๋ถ
if x-1 >=0:
x-=1
dice[1],dice[2],dice[4],dice[5] = dice[2],dice[4],dice[5],dice[1]
print(dice[2])
if arr[x][y] == 0:
arr[x][y] = dice[5]
else:
dice[5] = arr[x][y]
arr[x][y] = 0
elif i == 4: # ๋‚จ
if x+1 < n:
x+=1
dice[1],dice[2],dice[4],dice[5] = dice[5],dice[1],dice[2],dice[4]
print(dice[2])
if arr[x][y] == 0:
arr[x][y] = dice[5]
else:
dice[5] = arr[x][y]
arr[x][y] = 0
40 changes: 40 additions & 0 deletions yuyu0830/DP/1562.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <iostream>

#define MOD 1000000000

using namespace std;

int arr[101][10][1024] = {0, };

int main() {
int n; cin >> n;

for (int i = 1; i < 10; i++) {
arr[1][i][1 << i] = 1;
}

for (int i = 2; i <= n; i++) {
for (int j = 0; j < 10; j++) {
for (int k = 0; k < 1024; k++) {
if (j) {
arr[i][j][k | (1 << j)] += arr[i - 1][j - 1][k];
arr[i][j][k | (1 << j)] %= MOD;
}

if (j != 9) {
arr[i][j][k | (1 << j)] += arr[i - 1][j + 1][k];
arr[i][j][k | (1 << j)] %= MOD;
}
}
}
}

int ans = 0;

for (int i = 0; i < 10; i++) {
ans += arr[n][i][1023];
ans %= MOD;
}

printf("%d\n", ans);
}
36 changes: 36 additions & 0 deletions yuyu0830/LCS/9252.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <iostream>
#include <string>

using namespace std;

int arr[1001][1001] = {0, };
string str1, str2;

void print(int x, int y) {
if (!arr[x][y]) return;

if (str1[x - 1] == str2[y - 1]) {
print(x - 1, y - 1);
printf("%c", str1[x - 1]);
return;
}

arr[x - 1][y] > arr[x][y - 1] ? print(x - 1, y) : print(x, y - 1);
}

int main() {
cin >> str1 >> str2;

int len1 = str1.size(), len2 = str2.size();

for (int i = 0; i <= len1; i++) {
for (int j = 0; j <= len2; j++) {
if (!i || !j) arr[i][j] = 0;
else if (str1[i - 1] == str2[j - 1]) arr[i][j] = arr[i - 1][j - 1] + 1;
else arr[i][j] = max(arr[i][j - 1], arr[i - 1][j]);
}
}

printf("%d\n", arr[len1][len2]);
print(len1, len2);
}
2 changes: 2 additions & 0 deletions yuyu0830/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@
| 19์ฐจ์‹œ | 2024.07.12 | ์žฌ๊ท€ | [์šฐ์ˆ˜๋งˆ์„](https://www.acmicpc.net/problem/1949) | - |
| 20์ฐจ์‹œ | 2024.07.22 | LIS | [๊ฐ€์žฅ ๊ธด ์ฆ๊ฐ€ํ•˜๋Š” ๋ถ€๋ถ„ ์ˆ˜์—ด 5](https://www.acmicpc.net/problem/14003) | - |
| 21์ฐจ์‹œ | 2024.07.23 | ์ˆ˜ํ•™ | [1์˜ ๊ฐœ์ˆ˜ ์„ธ๊ธฐ](https://www.acmicpc.net/problem/9527) | - |
| 22์ฐจ์‹œ | 2024.08.05 | DP | [๊ณ„๋‹จ ์ˆ˜](https://www.acmicpc.net/problem/1562) | - |
| 23์ฐจ์‹œ | 2024.08.05 | LCS | [LCS 2](https://www.acmicpc.net/problem/9252) | - |
| 24์ฐจ์‹œ | 2024.08.14 | ์œ„์ƒ์ •๋ ฌ | [์ค„ ์„ธ์šฐ๊ธฐ](https://www.acmicpc.net/problem/2252) | - |
---

0 comments on commit ed7d392

Please sign in to comment.