Skip to content

Commit 513eff4

Browse files
committed
edit gitignore(ignore cpp project folder)
1 parent 00816b7 commit 513eff4

6 files changed

Lines changed: 215 additions & 254 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Project Path
2+
AA/

인프런_알고리즘_강의/김태원/AA/.gitignore

Lines changed: 0 additions & 41 deletions
This file was deleted.

인프런_알고리즘_강의/김태원/AA/AA.h

Whitespace-only changes.
Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,60 @@
1-
## 문제)
2-
아래 그림과 같은 이진트리를 넓이우선탐색해 보세요. 간선 정보 6개를 입력받아 처리해보세
3-
요.
4-
5-
![image](https://user-images.githubusercontent.com/75019048/175427734-14b043d6-9791-407b-bb31-d8035e49ffd8.png)
6-
7-
넓이 우선 탐색 : 1 2 3 4 5 6 7
8-
9-
### 입력
10-
1 2\
11-
1 3\
12-
2 4\
13-
2 5\
14-
3 6\
15-
3 7
16-
17-
18-
### 출력
19-
1 2 3 4 5 6 7
20-
21-
### 모범 답안
22-
``` Cpp
23-
#include <iostream>
24-
#include <vector>
25-
using namespace std;
26-
int Q[100], front = -1, back = -1, ch[10];
27-
vector<int> map[10];
28-
int main() {
29-
FILE* fp = nullptr;
30-
freopen_s(&fp, "input.txt", "rt", stdin);
31-
int i = 0, a = 0, b = 0, x = 0;
32-
for (i = 1; i <= 6; i++) {
33-
cin >> a >> b;
34-
map[a].push_back(b);
35-
map[b].push_back(a);
36-
}
37-
38-
Q[++back] = 1;
39-
ch[1] = 1;
40-
while (front < back) { // Q에 자료가 더 있을 때까지 순환
41-
x = Q[++front];
42-
cout << x << " ";
43-
for (i = 0; i < map[x].size(); i++) {
44-
if (ch[map[x][i]] == 0) {
45-
ch[map[x][i]] = 1;
46-
Q[++back] = map[x][i];
47-
}
48-
}
49-
}
50-
51-
return 0;
52-
}
53-
```
54-
55-
### 회고
56-
57-
1. BFS(넓이 우선 탐색 또는 레벨 탐색)
58-
- Root node 이후 탐색을 할 때 root node의 자식들을 모두 탐색을 하는 것이 넓이 우선 탐색이다.
59-
2. Queue를 저렇게 사용하는 이유는 실제로 출력을 하기 위한 pos 값(front)과 데이터를 저장하기 위한 pos 값(back)을 각각 구분하기 위함이다.
60-
1+
## 문제)
2+
아래 그림과 같은 이진트리를 넓이우선탐색해 보세요. 간선 정보 6개를 입력받아 처리해보세
3+
요.
4+
5+
![image](https://user-images.githubusercontent.com/75019048/175427734-14b043d6-9791-407b-bb31-d8035e49ffd8.png)
6+
7+
넓이 우선 탐색 : 1 2 3 4 5 6 7
8+
9+
### 입력
10+
1 2\
11+
1 3\
12+
2 4\
13+
2 5\
14+
3 6\
15+
3 7
16+
17+
18+
### 출력
19+
1 2 3 4 5 6 7
20+
21+
### 모범 답안
22+
``` Cpp
23+
#include <iostream>
24+
#include <vector>
25+
using namespace std;
26+
int Q[100], front = -1, back = -1, ch[10];
27+
vector<int> map[10];
28+
int main() {
29+
FILE* fp = nullptr;
30+
freopen_s(&fp, "input.txt", "rt", stdin);
31+
int i = 0, a = 0, b = 0, x = 0;
32+
for (i = 1; i <= 6; i++) {
33+
cin >> a >> b;
34+
map[a].push_back(b);
35+
map[b].push_back(a);
36+
}
37+
38+
Q[++back] = 1;
39+
ch[1] = 1;
40+
while (front < back) { // Q에 자료가 더 있을 때까지 순환
41+
x = Q[++front];
42+
cout << x << " ";
43+
for (i = 0; i < map[x].size(); i++) {
44+
if (ch[map[x][i]] == 0) {
45+
ch[map[x][i]] = 1;
46+
Q[++back] = map[x][i];
47+
}
48+
}
49+
}
50+
51+
return 0;
52+
}
53+
```
54+
55+
### 회고
56+
57+
1. BFS(넓이 우선 탐색 또는 레벨 탐색)
58+
- Root node 이후 탐색을 할 때 root node의 자식들을 모두 탐색을 하는 것이 넓이 우선 탐색이다.
59+
2. Queue를 저렇게 사용하는 이유는 실제로 출력을 하기 위한 pos 값(front)과 데이터를 저장하기 위한 pos 값(back)을 각각 구분하기 위함이다.
60+
Lines changed: 74 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,74 @@
1-
## 문제)
2-
다음 그래프에서 1번 정점에서 각 정점으로 가는 최소 이동 간선수를 출력하세요.
3-
4-
![image](https://user-images.githubusercontent.com/75019048/175427796-ca4404b2-cc3b-4fbe-b381-e6603e5a4b0c.png)
5-
6-
### 입력 설명
7-
첫째 줄에는 정점의 수 N(1<=N<=20)와 간선의 수 M가 주어진다. 그 다음부터 M줄에 걸쳐 연
8-
결정보가 주어진다.
9-
10-
### 출력 설명
11-
1번 정점에서 각 정점으로 가는 최소 간선수를 2번 정점부터 차례대로 출력하세요.
12-
13-
### 입력
14-
6 9\
15-
1 3\
16-
1 4\
17-
2 1\
18-
2 5\
19-
3 4\
20-
4 5\
21-
4 6\
22-
6 2\
23-
6 5
24-
25-
### 출력
26-
2 : 3\
27-
3 : 1\
28-
4 : 1\
29-
5 : 2\
30-
6 : 2
31-
32-
### 모범 답안
33-
``` Cpp
34-
#include <iostream>
35-
#include <queue>
36-
using namespace std;
37-
int ch[21], res[21];
38-
vector<int> map[21];
39-
int main() {
40-
FILE* fp = nullptr;
41-
freopen_s(&fp, "input.txt", "rt", stdin);
42-
int i = 0, n = 0, m = 0, a = 0, b = 0, x = 0;
43-
queue<int> q;
44-
cin >> n >> m;
45-
for (i = 1; i <= m; i++) {
46-
cin >> a >> b;
47-
map[a].push_back(b);
48-
}
49-
q.push(1);
50-
ch[1] = 1;
51-
while (q.size() > 0) {
52-
x = q.front();
53-
q.pop();
54-
for (i = 0; i < map[x].size(); i++) {
55-
if (ch[map[x][i]] == 0) {
56-
ch[map[x][i]] = 1;
57-
q.push(map[x][i]);
58-
res[map[x][i]] = res[x] + 1;
59-
}
60-
}
61-
}
62-
63-
for (i = 2; i <= n; i++) {
64-
cout << i << " : " << res[i] << endl;
65-
}
66-
67-
return 0;
68-
}
69-
```
70-
71-
### 회고
72-
73-
1. 풀이 전략만 듣고 단 한번에 구현 성공한 문제.
74-
2. 이 맛에 알고리즘 공부를 하는가보다.
1+
## 문제)
2+
다음 그래프에서 1번 정점에서 각 정점으로 가는 최소 이동 간선수를 출력하세요.
3+
4+
![image](https://user-images.githubusercontent.com/75019048/175427796-ca4404b2-cc3b-4fbe-b381-e6603e5a4b0c.png)
5+
6+
### 입력 설명
7+
첫째 줄에는 정점의 수 N(1<=N<=20)와 간선의 수 M가 주어진다. 그 다음부터 M줄에 걸쳐 연
8+
결정보가 주어진다.
9+
10+
### 출력 설명
11+
1번 정점에서 각 정점으로 가는 최소 간선수를 2번 정점부터 차례대로 출력하세요.
12+
13+
### 입력
14+
6 9\
15+
1 3\
16+
1 4\
17+
2 1\
18+
2 5\
19+
3 4\
20+
4 5\
21+
4 6\
22+
6 2\
23+
6 5
24+
25+
### 출력
26+
2 : 3\
27+
3 : 1\
28+
4 : 1\
29+
5 : 2\
30+
6 : 2
31+
32+
### 모범 답안
33+
``` Cpp
34+
#include <iostream>
35+
#include <queue>
36+
using namespace std;
37+
int ch[21], res[21];
38+
vector<int> map[21];
39+
int main() {
40+
FILE* fp = nullptr;
41+
freopen_s(&fp, "input.txt", "rt", stdin);
42+
int i = 0, n = 0, m = 0, a = 0, b = 0, x = 0;
43+
queue<int> q;
44+
cin >> n >> m;
45+
for (i = 1; i <= m; i++) {
46+
cin >> a >> b;
47+
map[a].push_back(b);
48+
}
49+
q.push(1);
50+
ch[1] = 1;
51+
while (q.size() > 0) {
52+
x = q.front();
53+
q.pop();
54+
for (i = 0; i < map[x].size(); i++) {
55+
if (ch[map[x][i]] == 0) {
56+
ch[map[x][i]] = 1;
57+
q.push(map[x][i]);
58+
res[map[x][i]] = res[x] + 1;
59+
}
60+
}
61+
}
62+
63+
for (i = 2; i <= n; i++) {
64+
cout << i << " : " << res[i] << endl;
65+
}
66+
67+
return 0;
68+
}
69+
```
70+
71+
### 회고
72+
73+
1. 풀이 전략만 듣고 단 한번에 구현 성공한 문제.
74+
2. 이 맛에 알고리즘 공부를 하는가보다.

0 commit comments

Comments
 (0)