Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- 시뮬레이션
- 레벨3
- 삼성
- substr
- 레벨2
- 완전탐색
- 코딩테스트
- STL
- 이런게4문제
- 백준
- 프로그래머스
- Sort
- 2018
- priority_queue
- dp
- 코딩스킬
- swea
- 모의SW역량테스트
- Set
- 문자열
- find
- 백트래킹
- BFS
- 삼성SW테스트
- Map
- KAKAO
- 삼성SW역량테스트
- C++
- dfs
- 브루트포스
Archives
- Today
- Total
-
[프로그래머스] 레벨 3 - 네트워크 본문
https://programmers.co.kr/learn/courses/30/lessons/43162
코딩테스트 연습 - 네트워크 | 프로그래머스
네트워크란 컴퓨터 상호 간에 정보를 교환할 수 있도록 연결된 형태를 의미합니다. 예를 들어, 컴퓨터 A와 컴퓨터 B가 직접적으로 연결되어있고, 컴퓨터 B와 컴퓨터 C가 직접적으로 연결되어 있을 때 컴퓨터 A와 컴퓨터 C도 간접적으로 연결되어 정보를 교환할 수 있습니다. 따라서 컴퓨터 A, B, C는 모두 같은 네트워크 상에 있다고 할 수 있습니다. 컴퓨터의 개수 n, 연결에 대한 정보가 담긴 2차원 배열 computers가 매개변수로 주어질 때, 네트워크
programmers.co.kr
서로 분리된 그래프의 개수를 찾는 문제다.
양방향 간선으로 연결된 그래프들의 정보가 인접행렬로 주어지는데 이를 활용해
분리된 그래프가 몇 개인지 확인하는 문제다.
나는 BFS로 해답을 찾았다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
#include <string>
#include <vector>
#include <queue>
using namespace std;
bool check[200];
int answer = 0;
void falsing(int n){
for(int i=0; i<n; i++) check[i] = false;
}
int solution(int n, vector<vector<int>> computers) {
falsing(n);
for(int i=0; i<n; i++){
if(!check[i]){
queue<int> q;
check[i] = true;
q.push(i);
while(!q.empty()){
int front = q.front();
q.pop();
for(int j=0; j<n; j++){
int whether = computers[front][j];
if(whether == 1 && !check[j]){
check[j] = true;
q.push(j);
}
}
}
answer++;
}
}
return answer;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs |
'1-4. 프로그래머스' 카테고리의 다른 글
[프로그래머스_레벨 3] 여행 경로 (DFS) (0) | 2020.02.10 |
---|---|
[프로그래머스_레벨 3] 2 x n 타일링 (0) | 2020.02.10 |
[프로그래머스] 레벨 2 - 타겟 넘버 (0) | 2020.02.07 |
[프로그래머스] 레벨 2 - 카펫 (0) | 2020.02.07 |
[프로그래머스] 레벨 2 - H-Index (0) | 2020.02.07 |
Comments