diff --git a/InSange/README.md b/InSange/README.md index 0828da4..a29d500 100644 --- a/InSange/README.md +++ b/InSange/README.md @@ -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)] -======= --- diff --git a/dhlee777/README.md b/dhlee777/README.md index f7e009a..752ce64 100644 --- a/dhlee777/README.md +++ b/dhlee777/README.md @@ -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)| \ No newline at end of file diff --git "a/dhlee777/bfs/\355\206\240\353\247\210\355\206\240.cpp" "b/dhlee777/bfs/\355\206\240\353\247\210\355\206\240.cpp" new file mode 100644 index 0000000..8b67176 --- /dev/null +++ "b/dhlee777/bfs/\355\206\240\353\247\210\355\206\240.cpp" @@ -0,0 +1,71 @@ +#include +#include +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; + + } +}; +queueq; +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; + +} \ No newline at end of file diff --git "a/dhlee777/dfs/\354\240\201\353\241\235\354\203\211\354\225\275.cpp" "b/dhlee777/dfs/\354\240\201\353\241\235\354\203\211\354\225\275.cpp" new file mode 100644 index 0000000..11902db --- /dev/null +++ "b/dhlee777/dfs/\354\240\201\353\241\235\354\203\211\354\225\275.cpp" @@ -0,0 +1,55 @@ +#include +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; +} \ No newline at end of file diff --git "a/dhlee777/\353\254\270\354\236\220\354\227\264\354\262\230\353\246\254/AC.cpp" "b/dhlee777/\353\254\270\354\236\220\354\227\264\354\262\230\353\246\254/AC.cpp" new file mode 100644 index 0000000..55ed379 --- /dev/null +++ "b/dhlee777/\353\254\270\354\236\220\354\227\264\354\262\230\353\246\254/AC.cpp" @@ -0,0 +1,86 @@ +#include +#include +#include +#include +using namespace std; +vectorv; //迭 ҵ +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 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().swap(v); //ٸ ׽Ʈ̽ ʱȭ + + } + + +} \ No newline at end of file diff --git "a/seongwon030/DP/1,2,3 \353\215\224\355\225\230\352\270\2603.py" "b/seongwon030/DP/1,2,3 \353\215\224\355\225\230\352\270\2603.py" new file mode 100644 index 0000000..a891a28 --- /dev/null +++ "b/seongwon030/DP/1,2,3 \353\215\224\355\225\230\352\270\2603.py" @@ -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]) \ No newline at end of file diff --git "a/seongwon030/DP/\355\225\251\353\266\204\355\225\264.py" "b/seongwon030/DP/\355\225\251\353\266\204\355\225\264.py" new file mode 100644 index 0000000..13e1241 --- /dev/null +++ "b/seongwon030/DP/\355\225\251\353\266\204\355\225\264.py" @@ -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]) \ No newline at end of file diff --git "a/seongwon030/bfs/\352\262\260\355\230\274\354\213\235.py" "b/seongwon030/bfs/\352\262\260\355\230\274\354\213\235.py" new file mode 100644 index 0000000..9779c02 --- /dev/null +++ "b/seongwon030/bfs/\352\262\260\355\230\274\354\213\235.py" @@ -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) \ No newline at end of file diff --git "a/seongwon030/\354\210\230\355\225\231/\354\227\260\354\206\215 \355\225\251.py" "b/seongwon030/\354\210\230\355\225\231/\354\227\260\354\206\215 \355\225\251.py" new file mode 100644 index 0000000..d931227 --- /dev/null +++ "b/seongwon030/\354\210\230\355\225\231/\354\227\260\354\206\215 \355\225\251.py" @@ -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) diff --git "a/yuyu0830/\341\204\220\341\205\241\341\206\267\341\204\211\341\205\242\341\206\250/12851.cpp" "b/yuyu0830/\341\204\220\341\205\241\341\206\267\341\204\211\341\205\242\341\206\250/12851.cpp" deleted file mode 100644 index bec7364..0000000 --- "a/yuyu0830/\341\204\220\341\205\241\341\206\267\341\204\211\341\205\242\341\206\250/12851.cpp" +++ /dev/null @@ -1,85 +0,0 @@ -// BFS 골드 4 숨바꼭질 2 https://www.acmicpc.net/problem/12851 -#include -#include -#include - -using namespace std; - -int n, k; -int dist[100001] = {0, }; -bool visited[100001] = {0, }; - -void solve() { - // 2개의 큐를 번갈아 사용하기 위한 큐 배열, 불리언 변수 - priority_queue, greater> q[2]; - bool e = false; - - // 현재 탐색에서 탐색중인 위치를 저장 - vector visitedVec; - - q[e].push(n); - dist[n] = 1; - visited[n] = 1; - - if (n == k) { - printf("0\n1"); - return; - } - - int time = 1, cnt = 0; - - while (true) { - while (!q[e].empty()) { - int cur = q[e].top(); - - q[e].pop(); - - for (int i : {cur - 1, cur * 2, cur + 1}) { - if (i < 0 || i > 100000) continue; - - // 목표 위치에 도착한 경우 경우의 수 저장 - if (i == k) cnt += dist[cur] + 1; - - // 첫 방문인 경우 다음 탐색 큐에 저장 - if (!dist[i]) { - q[!e].push(i); - visitedVec.push_back(i); - } - - // 방문한 위치에 현재 위치의 경우의 수 더하기 - // 이전 탐색에서 탐색한 위치는 방문 안하도록 - if (!visited[i]) - dist[i] += dist[cur]; - - // 탐색 도중 숫자가 커지면 탐색을 종료, 탐색중 큐 비우기 - if (cur > k) break; - } - - // 숫자가 커져서 탐색을 종료하면 남은 큐는 비워주기 - if (cur > k) { - q[e] = priority_queue , greater> (); - break; - } - } - - if (cnt) { - printf("%d\n%d", time, dist[k]); - break; - } - - // 이번 탐색에서 방문한 노드들 전부 표시 해주기 - while (!visitedVec.empty()) { - int v = visitedVec.back(); - visitedVec.pop_back(); - visited[v] = 1; - } - - e = !e; - time++; - } -} - -int main() { - cin >> n >> k; - solve(); -} \ No newline at end of file diff --git "a/yuyu0830/\352\267\270\353\246\254\353\224\224/1202.cpp" "b/yuyu0830/\352\267\270\353\246\254\353\224\224/1202.cpp" new file mode 100644 index 0000000..0799d4d --- /dev/null +++ "b/yuyu0830/\352\267\270\353\246\254\353\224\224/1202.cpp" @@ -0,0 +1,56 @@ +#include +#include +#include +#include + +using namespace std; + +typedef pair ii; + +#define fastio cin.tie(NULL); cin.sync_with_stdio(false); + +ii gems[300001]; +int bags[300001] = {0, }; + +priority_queue q; + +int main() { + fastio + + // input + int n, k; cin >> n >> k; + + for (int i = 0; i < n; i++) + cin >> gems[i].first >> gems[i].second; + + for (int i = 0; i < k; i++) + cin >> bags[i]; + + // Sort gems, bags ascending order + // gems sort by weight + sort(gems, gems + n); + sort(bags, bags + k); + + // ans can be more then int max value + // 300,000 * 1,000,000 + long long int ans = 0; + int cnt = 0; + + for (int i = 0; i < k; i++) { + int curBag = bags[i]; + + // push all the gems that can put in current bag into the priority queue + while (cnt < n && gems[cnt].first <= curBag) { + q.push(gems[cnt].second); + cnt++; + } + + // if queue is not empty, top of queue will be max price that can get in current bag + if (!q.empty()) { + ans += q.top(); + q.pop(); + } + } + + printf("%lld\n", ans); +} \ No newline at end of file diff --git "a/yuyu0830/\354\240\225\353\240\254/23970.cpp" "b/yuyu0830/\354\240\225\353\240\254/23970.cpp" new file mode 100644 index 0000000..c7120c1 --- /dev/null +++ "b/yuyu0830/\354\240\225\353\240\254/23970.cpp" @@ -0,0 +1,58 @@ +#include + +#define fastio cin.tie(NULL); cin.sync_with_stdio(false); + +using namespace std; + +int arr[2][10001] = {0, }; +int n, arrPtr = 0; + +bool same() { + // start at 'arrPtr' + for (int i = arrPtr; i < n; i++) { + // if diff, terminate this function + if (arr[0][i] != arr[1][i]) return false; + // if same, then that index will same forever. no reason to compare again. + arrPtr++; + } + return true; +} + +int main() { + fastio + cin >> n; + for (int i = 0; i < 2; i++) + for (int j = 0; j < n; j++) + cin >> arr[i][j]; + + int rnd = n - 1, ptr = 0; + + // it can be same before sort + if (same()) { + printf("1\n"); + return 0; + } + + while (rnd) { + // sort [0] to [ptr - rnd] + int a = arr[0][ptr]; + int b = arr[0][ptr + 1]; + + arr[0][ptr] = min(a, b); + arr[0][ptr + 1] = max(a, b); + + // if this index is last index in this round + if (++ptr == rnd) { + // next round + ptr = 0; + rnd--; + } + + if (same()) { + // if arr is same + printf("1\n"); + return 0; + } + } + printf("0\n"); +} \ No newline at end of file diff --git "a/yuyu0830/\341\204\220\341\205\241\341\206\267\341\204\211\341\205\242\341\206\250/1865.cpp" "b/yuyu0830/\355\203\220\354\203\211/1865.cpp" similarity index 100% rename from "yuyu0830/\341\204\220\341\205\241\341\206\267\341\204\211\341\205\242\341\206\250/1865.cpp" rename to "yuyu0830/\355\203\220\354\203\211/1865.cpp"