일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- C++
- 알고리즘
- Conjugate Gradient
- 2020.03.16
- class
- graphics
- TIP
- Til
- 2020.02.23
- ppt
- stretch force
- 알고리즘연습
- 백준
- 독서
- 프로그래머스
- 학습용
- rendering pipeline
- 논문
- UNORDERED_MAP
- numerical method
- Overloading
- Implicit method
- C
- game jam
- oprerator
- algorithm #알고리즘 #백준
- 참조자
- sparse matrix
- Algorithm
- ComputeShader
Archives
- Today
- Total
OSgood의 개발일기
[백준] 2487 섞기 수열 본문
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 49 50 51 52 53 54 55 56 57 58 | #include <bits/stdc++.h> using namespace std; int input[20202]; int dptable[20202]; int n; int calcuGCD(int a, int b) { int c; while (b != 0) { c = a % b; a = b; b = c; } return a; } inline int lcm(int a, int b) { return a / calcuGCD(a, b) * b; } int cycle(int start) { int cnt = 0; int result = start; int i = start; do { i = input[i]; dptable[i] = 1; cnt++; }while (result != i); return cnt; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> input[i]; } int result = 1; for (int i = 1; i <= n; i++) { if (dptable[i]) continue; int now = cycle(i); result = lcm(result, now); } cout << result; } | cs |
'Algorithm > Algorithm 문제 연습' 카테고리의 다른 글
[백준] 2472 체인점 (0) | 2020.04.12 |
---|---|
[백준] 2473 세 용액 (0) | 2020.04.11 |
[백준] 2436 공약수 (0) | 2020.03.29 |
[백준] 2517 달리기 (0) | 2020.03.29 |
[백준] 8986 전봇대 (0) | 2020.03.22 |
Comments