-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 24-yuyu0830
- Loading branch information
Showing
8 changed files
with
285 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | | ||
|
||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters