일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 완전 탐색
- 에라토스테네스의 체
- 동적 계획법
- tcache
- 이진 탐색
- BOF
- ROP
- 분할 정복
- heap
- 수학
- 포맷스트링버그
- 큐
- 다이나믹 프로그래밍
- 이분 탐색
- 문자열 처리
- House of Orange
- syscall
- 연결리스트
- RTL
- fsb
- 브루트 포스
- 스위핑 알고리즘
- 투 포인터
- DFS
- 스택
- OOB
- off by one
- 백트래킹
- BFS
- 이진트리
Archives
- Today
- Total
SDJ( 수돈재 아님 ㅎ )
[C++] 10451 - 순열 사이클 본문
문제 링크 : https://www.acmicpc.net/problem/10451
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
#include<iostream>
#include<algorithm>
#include<cstring> // for memset
#define endl '\n'
using namespace std;
int cycle[1005];
bool memo[1005];
int T;
int dfs(int start, int end, int n)
{
for(int i = 1; i <= n; ++i)
{
end = cycle[end];
memo[end] = 1;
if(start == end)
return 1;
}
}
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
int cnt;
cin >> T;
for(int i = 0; i < T; ++i)
{
cnt = 0;
cin >> n;
for(int j = 1 ; j <= n; ++j)
cin >> cycle[j];
for(int j = 1; j <= n; ++j)
if(!memo[j])
cnt += dfs(j, j, n);
cout << cnt << endl;
memset(cycle, 0, sizeof(cycle));
memset(memo, 0, sizeof(memo));
}
return 0;
}
|
'알고리즘 > Backjoon' 카테고리의 다른 글
[Python3] 16212 - 정열적인 정렬 (0) | 2020.01.05 |
---|---|
[Python3] 2355 - 시그마 (0) | 2020.01.05 |
[Python3] 2935 - 소음 (0) | 2020.01.05 |
[C++] 15657 - N과 M (8) (0) | 2020.01.05 |
[C++] 15656 - N과 M (7) (0) | 2020.01.05 |
Comments