8922 두찌 수열
2019. 8. 12. 12:13ㆍ알고리즘/백준
1000번까지 수행한 후 zero가 아니라면 loop이다
문제: https://www.acmicpc.net/problem/8922
깃허브주소: https://github.com/surinoel/boj/blob/master/8922.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cmath> | |
#include <vector> | |
#include <iostream> | |
using namespace std; | |
int main(void) { | |
ios_base::sync_with_stdio(false); | |
cin.tie(nullptr); | |
int tc; | |
cin >> tc; | |
while (tc--) { | |
int n; | |
cin >> n; | |
vector<int> a(n); | |
for (int i = 0; i < n; i++) { | |
cin >> a[i]; | |
} | |
bool ok = true; | |
for (int i = 0; i < 1000; i++) { | |
vector<int> b(n); | |
for (int j = 0; j < n; j++) { | |
if (j == n - 1) { | |
b[j] = abs(a[j] - a[0]); | |
} | |
else { | |
b[j] = abs(a[j] - a[j + 1]); | |
} | |
} | |
bool iszero = true; | |
for (int j = 0; j < n; j++) { | |
if (b[j] != 0) { | |
iszero = false; | |
break; | |
} | |
} | |
if (iszero) { | |
ok = false; | |
break; | |
} | |
a = b; | |
} | |
if (!ok) { | |
cout << "ZERO\n"; | |
} | |
else { | |
cout << "LOOP\n"; | |
} | |
} | |
return 0; | |
} |
'알고리즘 > 백준' 카테고리의 다른 글
17406 배열 돌리기 4 (0) | 2019.08.13 |
---|---|
6087 레이저 통신 (0) | 2019.08.13 |
16236 아기 상어 (0) | 2019.08.10 |
17144 미세먼지 안녕 (0) | 2019.08.10 |
16986 인싸들의 가위바위보 (0) | 2019.08.10 |