Skip to content

Commit

Permalink
Merge branch 'main' into 9-kjs254
Browse files Browse the repository at this point in the history
  • Loading branch information
kjs254 authored Mar 22, 2024
2 parents c201d2f + b45efe9 commit abfe43d
Show file tree
Hide file tree
Showing 12 changed files with 446 additions and 11 deletions.
18 changes: 10 additions & 8 deletions YIM2UL2ET/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

| ์ฐจ์‹œ | ๋‚ ์งœ | ๋ฌธ์ œ์œ ํ˜• | ๋งํฌ | ํ’€์ด |
|:----:|:---------:|:----:|:-----:|:----:|
| 1์ฐจ์‹œ | 2024.02.12 | ๊ทธ๋ฆฌ๋”” | [BOJ 18310](https://www.acmicpc.net/problem/18310) | [BOJ 18310 ํ’€์ด](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/3) |
| 2์ฐจ์‹œ | 2024.02.15 | ๊ทธ๋ฆฌ๋”” | [BOJ 1263](https://www.acmicpc.net/problem/1263) | [BOJ 1449 ํ’€์ด](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/7) |
| 3์ฐจ์‹œ | 2024.02.18 | ์Šคํƒ | [BOJ 2504](https://www.acmicpc.net/problem/2504) | [BOJ 2504 ํ’€์ด](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/9) |
| 4์ฐจ์‹œ | 2024.02.21 | ๋ฑ | [BOJ 1021](https://www.acmicpc.net/problem/1021) | [BOJ 1021 ํ’€์ด](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/12) |
| 5์ฐจ์‹œ | 2024.02.24 | ํ | [BOJ 1158](https://www.acmicpc.net/problem/1158) | [BOJ 1158 ํ’€์ด](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/16) |
| 6์ฐจ์‹œ | 2024.02.27 | ์ •๋ ฌ | [BOJ 1599](https://www.acmicpc.net/problem/1599) | [BOJ 1599 ํ’€์ด](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/21) |
| 7์ฐจ์‹œ | 2024.03.01 | ์žฌ๊ท€ | [BOJ 2705](https://www.acmicpc.net/problem/2705) | [BOJ 2705 ํ’€์ด](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/23) |
| 8์ฐจ์‹œ | 2024.03.01 | ์žฌ๊ท€ | [BOJ 10994](https://www.acmicpc.net/problem/10994) | [BOJ 10994 ํ’€์ด](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/27) |
| 01์ฐจ์‹œ | 2024.02.12 | ๊ทธ๋ฆฌ๋”” | [BOJ 18310](https://www.acmicpc.net/problem/18310) | [BOJ 18310 ํ’€์ด](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/3) |
| 02์ฐจ์‹œ | 2024.02.15 | ๊ทธ๋ฆฌ๋”” | [BOJ 1263](https://www.acmicpc.net/problem/1263) | [BOJ 1449 ํ’€์ด](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/7) |
| 03์ฐจ์‹œ | 2024.02.18 | ์Šคํƒ | [BOJ 2504](https://www.acmicpc.net/problem/2504) | [BOJ 2504 ํ’€์ด](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/9) |
| 04์ฐจ์‹œ | 2024.02.21 | ๋ฑ | [BOJ 1021](https://www.acmicpc.net/problem/1021) | [BOJ 1021 ํ’€์ด](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/12) |
| 05์ฐจ์‹œ | 2024.02.24 | ํ | [BOJ 1158](https://www.acmicpc.net/problem/1158) | [BOJ 1158 ํ’€์ด](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/16) |
| 06์ฐจ์‹œ | 2024.02.27 | ์ •๋ ฌ | [BOJ 1599](https://www.acmicpc.net/problem/1599) | [BOJ 1599 ํ’€์ด](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/21) |
| 07์ฐจ์‹œ | 2024.03.01 | ์žฌ๊ท€ | [BOJ 2705](https://www.acmicpc.net/problem/2705) | [BOJ 2705 ํ’€์ด](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/23) |
| 08์ฐจ์‹œ | 2024.03.04 | ์žฌ๊ท€ | [BOJ 10994](https://www.acmicpc.net/problem/10994) | [BOJ 10994 ํ’€์ด](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/27) |
| 09์ฐจ์‹œ | 2024.03.07 | ์ž„์˜ ์ •๋ฐ€๋„ / ํฐ ์ˆ˜ ์—ฐ์‚ฐ && ์žฌ๊ท€ | [BOJ 1914](https://www.acmicpc.net/problem/1914) | [BOJ 1914 ํ’€์ด](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/29) |
| 10์ฐจ์‹œ | 2024.03.10 | ์Šคํƒ | [BOJ 1406](https://www.acmicpc.net/problem/1406) | [BOJ 1406 ํ’€์ด](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/31) |
---
28 changes: 28 additions & 0 deletions YIM2UL2ET/์Šคํƒ/10์ฐจ์‹œ - BOJ 1406.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <iostream>
#include <stack>

int main(void)
{
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);

int n;
char ch;
std::string str;
std::stack <char> stk1, stk2;

std::cin >> str >> n;
for (int i = 0; i < str.size(); i++) stk1.push(str[i]);

for (int i = 0; i < n; i++) {
std::cin >> ch;
if (ch == 'L' && !stk1.empty()) stk2.push(stk1.top()), stk1.pop();
else if (ch == 'D' && !stk2.empty()) stk1.push(stk2.top()), stk2.pop();
else if (ch == 'B' && !stk1.empty()) stk1.pop();
else if (ch == 'P') std::cin >> ch, stk1.push(ch);
}

while(stk1.size() > 0) stk2.push(stk1.top()), stk1.pop();
while(stk2.size() > 0) std::cout << stk2.top(), stk2.pop();
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <iostream>

std::string FindValue(int n)
{
std::string result = "1";
for (int i = 0; i < n; i++) {
for (int j = 0; j < result.size(); j++) {
result[j] = (result[j] - '0') * 2 + '0';
if (result[j] > '9') {
result[j] -= 10;
if (j == 0) result.insert(result.begin(), '1'), j++;
else result[j-1]++;
}
}
}
result[result.size()-1]--;
return result;
}

void Hanoi(int level, int start, int between, int end)
{
if (level == 1) std::cout << start << " " << end << "\n";
else {
Hanoi(level-1, start, end, between);
std::cout << start << " " << end << "\n";
Hanoi(level-1, between, start, end);
}
return;
}

int main(void) {
int n;
std::cin >> n;
std::cout << FindValue(n) << "\n";
if (!(n > 20)) Hanoi(n, 1, 2, 3);
return 0;
}
2 changes: 1 addition & 1 deletion kjs254/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
| 6์ฐจ์‹œ | 2024.02.27 | ์Šคํƒ | [๊ด„ํ˜ธ ํšŒ์ „ํ•˜๊ธฐ](https://school.programmers.co.kr/learn/courses/30/lessons/76502) | [#22](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/22) |
| 7์ฐจ์‹œ | 2024.03.01 | ๊ตฌํ˜„ | [์บ์‹œ](https://school.programmers.co.kr/learn/courses/30/lessons/17680) | [#24](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/24) |
| 8์ฐจ์‹œ | 2024.03.08 | ๊ตฌํ˜„ | [ํŠœํ”Œ](https://school.programmers.co.kr/learn/courses/30/lessons/64065) | [#30](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/30) |
| 9์ฐจ์‹œ | 2024.03.08 | ๊ตฌํ˜„ | [๋‰ด์Šค ํด๋Ÿฌ์Šคํ„ฐ๋ง](https://school.programmers.co.kr/learn/courses/30/lessons/17677) | [#33](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/33) |
| 9์ฐจ์‹œ | 2024.03.10 | ๊ตฌํ˜„ | [๋‰ด์Šค ํด๋Ÿฌ์Šคํ„ฐ๋ง](https://school.programmers.co.kr/learn/courses/30/lessons/17677) | [#33](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/33) |
---
18 changes: 18 additions & 0 deletions kjs254/๊ตฌํ˜„/ํŠœํ”Œ.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
def solution(s):
answer = []
dic = {}
s = s.replace('{','').replace('}','').split(',')

for n in s:
n = int(n)
if n not in dic:
dic[n] = 1
else:
dic[n]+= 1

dic_sorted = sorted(dic.items(), key=lambda x:x[1], reverse=True)

for d in dic_sorted:
answer.append(d[0])

return answer
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class BOJ1260_DFS์™€BFSํ”„๋กœ๊ทธ๋žจ {

static ArrayList<Integer>[] edges;
static boolean[] visited;
static StringBuilder answer = new StringBuilder();
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());

int n = Integer.parseInt(st.nextToken()); // ๋…ธ๋“œ ์ˆ˜
int m = Integer.parseInt(st.nextToken()); // ๊ฐ„์„  ์ˆ˜
int v = Integer.parseInt(st.nextToken()); // ์ถœ๋ฐœ ๋…ธ๋“œ

edges = new ArrayList[n + 1]; // ๊ฐ„์„  ๋ฐฐ์—ด
for (int i = 0; i < n + 1; i++) {
edges[i] = new ArrayList<>();
}

// ๊ฐ„์„  ์—ฐ๊ฒฐ
for (int i = 0; i < m; i++) {
st = new StringTokenizer(br.readLine());
int a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());

edges[a].add(b);
edges[b].add(a);
}

for (int i = 0; i < n + 1; i++) {
Collections.sort(edges[i]);
}

visited = new boolean[n + 1]; // ๋ฐฉ๋ฌธ ์—ฌ๋ถ€ ๋ฐฐ์—ด
dfs(v);
answer.append('\n');

visited = new boolean[n + 1];
bfs(v);
answer.append('\n');

System.out.print(answer);
}

public static void dfs(int now) {
answer.append(now);
answer.append(' ');

visited[now] = true;

for (int next : edges[now]) {
if (!visited[next]) {
dfs(next);
}
}
}

public static void bfs(int start) {
Queue<Integer> queue = new LinkedList<>();

// ์‹œ์ž‘ ๋…ธ๋“œ ์‚ฝ์ž…ํ•˜๊ธฐ
queue.add(start);
visited[start] = true;

// ํ๊ฐ€ ๋นŒ๋•Œ๊นŒ์ง€ ๋ฐ˜๋ณต
while (!queue.isEmpty()) {
int now = queue.poll();
answer.append(now);
answer.append(' ');

// now์— ์—ฐ๊ฒฐ๋œ node๋“ค์„ queue์— ์‚ฝ์ž…ํ•œ๋‹ค.
for (int next : edges[now]) {
if (!visited[next]) {
queue.add(next);
visited[next] = true;
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;

public class BOJ2178_๋ฏธ๋กœํƒ์ƒ‰ํ•˜๊ธฐ {

static int n;
static int m;

static boolean[][] field;
static boolean[][] visited;

static int[] dx = {1, -1, 0, 0};
static int[] dy = {0, 0, 1, -1};
public static void main(String[] args) throws IOException {
// ์ž…๋ ฅ
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());

n = Integer.parseInt(st.nextToken()); // ์„ธ๋กœ ํฌ๊ธฐ
m = Integer.parseInt(st.nextToken()); // ๊ฐ€๋กœ ํฌ๊ธฐ

// ๋ฏธ๋กœ ์„ ์–ธ
field = new boolean[n][m];
visited = new boolean[n][m];

// ๋ฏธ๋กœ ์ž…๋ ฅ
for (int i = 0; i < n; i++) {
String line = br.readLine();
for (int j = 0; j < m; j++) {
field[i][j] = line.charAt(j) == '1';
}
}

// ๋ฌธ์ œ ํ•ด๊ฒฐ
int answer = bfs(0, 0);

// ์ถœ๋ ฅ
System.out.println(answer);
}

public static int bfs(int i, int j) {
Queue<int[]> queue = new LinkedList<>();
queue.add(new int[]{i, j, 1});
visited[i][j] = true;

while (!queue.isEmpty()) {
int[] now = queue.poll();

if (now[0] == n - 1 && now[1] == m - 1) {
return now[2];
}

for (int k = 0; k < 4; k++) {
int x = now[0] + dx[k];
int y = now[1] + dy[k];

if (isInRange(x, y)) {
if (!visited[x][y] && field[x][y]) {
queue.add(new int[]{x, y, now[2] + 1});
visited[x][y] = true;
}
}
}
}

return 0;
}

public static boolean isInRange(int i, int j) {
return 0 <= i && i < n && 0 <= j && j < m;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package DFS;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class BOJ1167_ํŠธ๋ฆฌ์˜์ง€๋ฆ„๊ตฌํ•˜๊ธฐ {

static ArrayList<Edge>[] edges;
static boolean[] visited;
static int max;
static int farthest;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int V = Integer.parseInt(br.readLine());
edges = new ArrayList[V + 1];
for (int i = 0; i < V + 1; i++) {
edges[i] = new ArrayList<>();
}

for (int i = 0; i < V; i++) {
StringTokenizer st = new StringTokenizer(br.readLine());
int a = Integer.parseInt(st.nextToken());

while (true) {
int node = Integer.parseInt(st.nextToken());
if (node == -1) break;

int cost = Integer.parseInt(st.nextToken());
edges[a].add(new Edge(node, cost));
}
}

max = 0;
visited = new boolean[V+1];
dfs(1, 0);

max = 0;
visited = new boolean[V+1];
dfs(farthest, 0);

System.out.println(max);
}

public static void dfs(int node, int cost) {
visited[node] = true;
if (cost > max) {
farthest = node;
max = cost;
}

for (Edge edge : edges[node]) {
if (!visited[edge.node]) {
dfs(edge.node, cost + edge.cost);
}
}
}

static class Edge {
int node;
int cost;

public Edge(int node, int cost) {
this.node = node;
this.cost = cost;
}
}
}
Loading

0 comments on commit abfe43d

Please sign in to comment.