# Link
https://www.acmicpc.net/problem/11558
11558번: The Game of Death
첫 줄에는 테스트 케이스의 숫자 T가 주어지며, 이어서 T번에 걸쳐 테스트 케이스들이 주어진다. 매 테스트 케이스의 첫 줄에는 플레이어의 숫자 N(1 ≤ N ≤ 10,000)이 주어진다. 이어서 N줄에 걸쳐
www.acmicpc.net
# Code - C++
//
// BOJ
// ver.C++
//
// Created by GGlifer
//
// Open Source
#include <iostream>
using namespace std;
#define endl '\n'
#define len(x) (int)(x).length()
#define size(x) (int)(x).size()
#define str(x) to_string(x)
#define error logic_error("line " + str(__LINE__))
// Set up : Definitions
/* None */
// Set up : Global Variables
/* None */
// Set up : Functions Declaration
/* None */
int main()
{
// Set up : I/O
ios::sync_with_stdio(false);
cin.tie(nullptr);
// Set up : Input
int T; cin >> T;
while (T--) {
int N; cin >> N;
int A[N+1];
for (int i=1; i<=N; i++)
cin >> A[i];
// Process
int K = 0, c = 1;
while (K < N-1 && c != N) {
c = A[c];
K++;
}
// Control : Output
cout << ((c == N) ? K : 0) << endl;
}
}
// Helper Functions
/* None */
지적, 조언, 첨언 모두 환영합니다!!!
'Problem Solving > 백준' 카테고리의 다른 글
[ Problem Solving :: 백준 ] 1526 / 가장 큰 금민수 (0) | 2021.11.21 |
---|---|
[ Problem Solving :: 백준 ] 2473 / 세 용액 (0) | 2021.11.16 |
[ Problem Solving :: 백준 ] 2698 / 인접한 비트의 개수 (0) | 2021.11.16 |
[ Problem Solving :: 백준 ] 14606 / 피자 (Small) (0) | 2021.11.16 |
[ Problem Solving :: 백준 ] 2616 / 소형기관차 (0) | 2021.11.16 |