Skip to content

Commit

Permalink
Merge branch 'main' into 11-InSange
Browse files Browse the repository at this point in the history
  • Loading branch information
InSange authored May 20, 2024
2 parents e3ff94d + 11b5d76 commit a7badff
Show file tree
Hide file tree
Showing 13 changed files with 403 additions and 92 deletions.
1 change: 0 additions & 1 deletion InSange/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@
| 9μ°¨μ‹œ | 2024.04.12 | νž™ | [Top K Frequent Words](https://leetcode.com/submissions/detail/1180988760/) | [#9](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/28)]
| 10μ°¨μ‹œ | 2024.05.02 | μŠ€νƒ | [μ˜€μ•„μ‹œμŠ€ μž¬κ²°ν•©](https://www.acmicpc.net/problem/3015) | [#10](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/40)]
| 11μ°¨μ‹œ | 2024.05.02 | DFS | [숫자고λ₯΄κΈ°](https://www.acmicpc.net/problem/2668) | [#11](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/41)]
=======
---
7 changes: 1 addition & 6 deletions dhlee777/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,4 @@
| 4μ°¨μ‹œ | 2024.03.25 | BFS | [λ°”μ΄λŸ¬μŠ€](https://www.acmicpc.net/problem/2606) | [#17](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/17)|
| 5μ°¨μ‹œ | 2024.03.30 | mst | [μ΅œμ†ŒμŠ€νŒ¨λ‹νŠΈλ¦¬](https://www.acmicpc.net/problem/1197) | [#21](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/21)|
| 6μ°¨μ‹œ | 2024.04.04 | backtracking | [μŠ€νƒ€νŠΈμ™€λ§ν¬](https://www.acmicpc.net/problem/14889) | [#29](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/29)|
| 7μ°¨μ‹œ | 2024.04.08 | backtracking | [nκ³Όm(5)](https://www.acmicpc.net/problem/15654) | [#31](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/31)|





| 7μ°¨μ‹œ | 2024.04.08 | backtracking | [nκ³Όm(5)](https://www.acmicpc.net/problem/15654) | [#31](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/31)|
71 changes: 71 additions & 0 deletions dhlee777/bfs/ν† λ§ˆν† .cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include<iostream>
#include<queue>
using namespace std;
int tom[101][101][101]; //ν† λ§ˆν† μ˜ μƒνƒœλ₯Ό μ €μž₯ν•˜κΈ°μœ„ν•œ λ°°μ—΄
int col, row, height;
int x[6] = { 0,0,-1,1,0,0 };
int y[6] = { -1,1,0,0,0,0 };
int z[6] = { 0,0,0,0,1,-1 };
struct tomato { //ν† λ§ˆν† μ˜ μ’Œν‘œλ₯Ό μ €μž₯ν•˜κΈ°μœ„ν•œ ꡬ쑰체
int x1; //μ—΄
int y1; //ν–‰
int z1; //높이
tomato(int _x1, int _y1, int _z1) {
x1 = _x1; y1 = _y1; z1 = _z1;

}
};
queue<tomato>q;
void bfs() {
while (!q.empty()) {
tomato t = q.front();
q.pop();
for (int i = 0; i < 6; i++) { //νƒμƒ‰λ²”μœ„(상,ν•˜,쒌,우,μœ„,μ•„λž˜)
int _x = t.x1 + x[i];
int _y = t.y1 + y[i];
int _z = t.z1 + z[i];
if (_x < col && _x >= 0 && _y < row && _y >= 0 && _z < height && _z >= 0 && tom[_z][_y][_x] == 0) {
tom[_z][_y][_x] = tom[t.z1][t.y1][t.x1] + 1;
q.push(tomato(_x, _y, _z));

}
}


}

}
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> col >> row >> height;

for (int i = 0; i < height; i++) {
for (int j = 0; j < row; j++) {
for (int k = 0; k < col; k++) {
cin >> tom[i][j][k];
if (tom[i][j][k] == 1) //μ΅μ€ν† λ§ˆν† κ°€ λ“€μ–΄μžˆμœΌλ©΄
q.push(tomato(k, j, i)); //νƒμƒ‰μ‹œμž‘μ μ„μœ„ν•΄ κ·Έ μ’Œν‘œλ₯Ό 큐에 λ„£λŠ”λ‹€.
}
}
}

bfs(); //
int sum = 0;
for (int i = 0; i < height; i++) {
for (int j = 0; j < row; j++) {
for (int k = 0; k < col; k++) {
if (tom[i][j][k] == 0) //bfsν›„ μ•ˆμ΅μ€ν† λ§ˆν† κ°€ μžˆλ‹€λ©΄ λͺ¨λ‘μ΅μ§€λͺ»ν•˜λŠ” μƒν™©μ΄λ―€λ‘œ -1을 좜λ ₯
{
cout << -1;
return 0;
}
if (sum < tom[i][j][k]) sum = tom[i][j][k]; //bfs ν›„ κ±Έλ¦°μ‹œκ°„μ„ μ°ΎκΈ°μœ„ν•΄ tomλ°°μ—΄μ˜ μ΅œλŒ€κ°’μ„ μ°Ύμ•„ sum에 μ €μž₯ν•˜λŠ”κ³Όμ •

}
}
}

sum == 1 ? cout << 0 : cout << sum - 1;

}
55 changes: 55 additions & 0 deletions dhlee777/dfs/적둝색약.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include<iostream>
using namespace std;
char color[100][100]; //정상인이 λ³΄λŠ” κ·Έλ¦Ό
char color2[100][100]; //적둝색약이 λ³΄λŠ” κ·Έλ¦Ό
bool visited[100][100]; //정상인 그림의 λ°©λ¬Έμ—¬λΆ€
bool visited2[100][100]; //적둝색약 그림의 λ°©λ¬Έμ—¬λΆ€
string line; // ν•œμ€„ μž…λ ₯을 λ°›κΈ°μœ„ν•œ 슀트링
int siz; //그림의 ν•œ λ³€μ˜ 길이
int coun = 0; //정상인이 κ·Έλ¦Όμ„λ΄€μ„λ•Œ κ΅¬μ—­μ˜κ°œμˆ˜
int coun2 = 0; //적둝색약이 λ΄€μ„λ•Œ κ΅¬μ—­μ˜κ°œμˆ˜
int x[4]={0,0,-1,1}; //μƒν•˜μ’Œμš° 탐색을 μœ„ν•œ xμ’Œν‘œ 이동값
int y[4] = { -1,1,0,0 }; // yμ’Œν‘œ 이동값

void dfs(int a,int b,char color[][100], bool visited[][100]) { //x:νƒμƒ‰μ‹œμž‘ μ’Œν‘œ,y:νƒμƒ‰μ‹œμž‘ yμ’Œν‘œ color:μ •μƒμΈμ˜ 탐색인지 μ λ‘μƒ‰μ•½μ˜ 탐색인지
for (int i = 0; i < 4; i++) {
int a2 = a + x[i];
int b2 = b + y[i];
if (a2 >= 0 && a2 < siz && b2 >= 0 && b2 < siz && !visited[a2][b2]&&color[a][b]==color[a2][b2]) {
visited[a2][b2] = true;
dfs(a2, b2,color,visited);
}
}
}
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> siz;
for (int i = 0; i < siz; i++) { //color,clolor2배열에 그림을 μž…λ ₯λ°›μ•„ μ €μž₯ν•΄μ€€λ‹€.
cin >> line;
for (int j = 0; j < siz; j++) {
color[i][j] = line[j];
if (line[j] == 'R') color2[i][j] = 'G'; //적둝색약을 μœ„ν•΄ r을 g둜 λ‹€ λ°”κΏ”μ„œ μ €μž₯ν•΄μ€€λ‹€.
else color2[i][j] = line[j];
}
}

for (int i = 0; i < siz; i++) { //μ •μƒμΈμ˜ 탐색
for (int j = 0; j < siz; j++) {
if (!visited[i][j]) {
dfs(i,j,color,visited);
coun++;
}
}
}
for (int i = 0; i < siz; i++) { //μ λ‘μƒ‰μ•½μ˜ 탐색
for (int j = 0; j < siz; j++) {
if (!visited2[i][j]) {
dfs(i, j, color2,visited2);
coun2++;
}
}
}
cout << coun <<" "<< coun2;
return 0;
}
86 changes: 86 additions & 0 deletions dhlee777/λ¬Έμžμ—΄μ²˜λ¦¬/AC.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
vector<int>v; //λ°°μ—΄μ˜ μ›μ†Œλ“€μ„ μ €μž₯ν•  벑터
string a,b,nm; //a-λͺ…령어듀을 μ €μž₯ν•  string, b-배열을 μ €μž₯ν•  string
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t,num,start_idx,end_idx; //t-ν…ŒμŠ€νŠΈμΌ€μ΄μŠ€κ°œμˆ˜,num-μ›μ†Œμ˜κ°œμˆ˜,start_idx-μ‹œμž‘ 인덱슀,end_idx-끝인덱슀
int r_cnt = 0;
cin >> t;
while (t--) {
cin >> a>>num>>b;
start_idx = 0; end_idx = num - 1;
r_cnt = 0;
for (int i = 0; i <b.size(); i++) {
if (b[i] == '[' || b[i] == ']')
continue;
else if (b[i] == ',')
{
v.push_back(stoi(nm));
nm.clear();
}
else
nm = nm + b[i];

}
if(!nm.empty()) v.push_back(stoi(nm));
nm.clear();

for (int i = 0; i < a.size(); i++) {
if (a[i] == 'R')
r_cnt++;
else { //dλ₯Όμ‹€ν–‰ν• κ²½μš°
if (end_idx == -1) //λ²‘ν„°λ‚΄μ˜ μ›μ†Œκ°€ μ—†λŠ”κ²½μš°
{
r_cnt == 0;
end_idx--;
break;
}
if (r_cnt % 2) { //r이 ν™€μˆ˜λ²ˆλ‚˜μ™”μ„κ²½μš° μ‹œμž‘μΈλ±μŠ€μ™€ 끝인덱슀λ₯Ό λ°”κΏ”μ€€λ‹€.
int temp = start_idx;
start_idx = end_idx;
end_idx = temp;
}
if (start_idx > end_idx)
start_idx--;
else if (end_idx > start_idx)
start_idx++;
else end_idx = -1; //μ‹œμž‘μΈλ±μŠ€μ™€ λμΈλ±μŠ€κ°€ κ°™μ„κ²½μš°μ— μ›μ†ŒλŠ” ν•˜λ‚˜μ‘΄μž¬ν•˜λ―€λ‘œ dλ₯Ό μ‹€ν–‰ν• κ²½μš° 벑터가 λΉ„κ²Œλœλ‹€.
r_cnt = 0;
}
}
if (r_cnt != 0 && end_idx > -1&&r_cnt%2==1) { //μ œμΌλμ— r이 올경우 빈 벑터가 μ•„λ‹ˆκ³  rμ˜κ°œμˆ˜κ°€ ν™€μˆ˜μΌλ•Œ
int temp = start_idx;
start_idx = end_idx;
end_idx = temp;
}

if (end_idx == -2) cout << "error"<<"\n";
else if (end_idx == -1) cout << "[]"<<"\n";
else {
cout << "[";
if (start_idx >= end_idx) {
for (int i =start_idx; i>end_idx; i--) {
cout << v[i] << ",";
}
cout << v[end_idx]<<"]"<<"\n";
}
else {
for (int i = start_idx; i < end_idx; i++) {
cout << v[i] << ",";
}
cout << v[end_idx]<<"]"<<"\n";
}

}

vector<int>().swap(v); //λ‹€λ₯Έ ν…ŒμŠ€νŠΈμΌ€μ΄μŠ€λ₯Ό μœ„ν•œ 벑터 μ΄ˆκΈ°ν™”

}


}
11 changes: 11 additions & 0 deletions seongwon030/DP/1,2,3 λ”ν•˜κΈ°3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import sys

input = sys.stdin.readline
dp = [1,2,4,7]
p = 4
for i in range(int(input())):
n = int(input())
while(n>p):
dp.append((dp[p-3]+dp[p-2]+dp[p-1])%1000000009)
p+=1
print(dp[n-1])
13 changes: 13 additions & 0 deletions seongwon030/DP/ν•©λΆ„ν•΄.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
n,k = map(int,input().split())

mod = 1000000000

dp = [[0] * (n+1) for _ in range(k+1)] # 2차원 λ°°μ—΄
dp [0][0] = 1 # μ΄ˆκΈ°κ°’ μ„€μ •

for i in range(1,k+1):
for j in range(n+1):
dp[i][j] = dp[i-1][j] + dp[i][j-1]
dp[i][j] = dp[i][j] % mod

print(dp[k][n])
32 changes: 32 additions & 0 deletions seongwon030/bfs/κ²°ν˜Όμ‹.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from collections import deque
import sys

input = sys.stdin.readline

n = int(input())
m = int(input())
arr = [[0 for i in range(n)] for i in range(n)]

for i in range(m):
a,b = map(int,input().split())
arr[a-1][b-1] = 1 # λ…Έλ“œ μ €μž₯
arr[b-1][a-1] = 1
visited = [0 for i in range(len(arr))]

def bfs(start):
q = deque()
q.append(start)
visited[start] = 1
while q:
top = q.popleft()
for i in range(len(arr)):
if arr[top][i] == 1 and visited[i] == 0:
visited[i] = visited[top]+1
q.append(i)

bfs(0)
re = 0
for i in visited:
if i==2 or i==3:
re+=1
print(re)
20 changes: 20 additions & 0 deletions seongwon030/μˆ˜ν•™/연속 ν•©.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import math

n = int(input())
for i in range(n):
cnt = 0
k = int(input())
j = 2 # 적어도 2개 μ΄μƒμ˜ μ—°μ†λœ μžμ—°μˆ˜μ˜ ν•©
while True:
center_first = math.floor(k / j) # center 값을 μ΄ˆκΈ°ν™”
div = j // 2
if center_first < div:
break
if j % 2 == 0:
if ((center_first + center_first + 1) * div == k):
cnt += 1
elif j % 2 == 1:
if ((center_first * 2 * div + center_first) == k):
cnt += 1
j += 1
print(cnt)
Loading

0 comments on commit a7badff

Please sign in to comment.