# 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 */

 

 

지적, 조언, 첨언 모두 환영합니다!!!

# Link

https://www.acmicpc.net/problem/2698

 

2698번: 인접한 비트의 개수

첫째 줄에 테스트 케이스의 수 T(1 ≤ T ≤ 1,000)가 주어진다. 각 테스트 케이스는 한 줄로 이루어져 있고, 수 2개가 공백으로 구분되어 이루어져 있다. 첫 번째 수는 n이고, 두 번째 수는 k이다. n과

www.acmicpc.net

 

 

# Code - C++

//
//  BOJ
//  ver.C++
//
//  Created by GGlifer
//
//  Open Source

#include <iostream>
#include <cstring>

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);

    // Process
    const int MAX = 100;
    int dp[MAX+1][MAX+1][2];
    memset(dp, 0, sizeof(dp));

    dp[1][0][0] = dp[1][0][1] = 1;
    for (int i=2; i<=MAX; i++) {
        for (int j=0; j<=i-1; j++) {
            dp[i][j][0] = dp[i-1][j][0] + dp[i-1][j][1];
            dp[i][j][1] = dp[i-1][j][0] + ((j > 0) ? dp[i-1][j-1][1] : 0);
        }
    }

    // Set up : Input
    int T; cin >> T;

    while (T--) {
        int n, k;
        cin >> n >> k;

        // Process
        int ans = dp[n][k][0] + dp[n][k][1];

        // Control : Output
        cout << ans << endl;

    }
}

// Helper Functions
/* None */

 

 

지적, 조언, 첨언 모두 환영합니다!!!

# Link

https://www.acmicpc.net/problem/14606

 

14606번: 피자 (Small)

예제1의 입력이 1이므로, 게임 시작부터 갑이 분리할 수 있는 피자탑이 없습니다. 따라서 갑이 얻는 즐거움은 0입니다. 예제2의 정답 3은 다음과 같은 과정을 통해 얻어집니다. 먼저 놀이를 시작

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
int f(int n);


int main()
{
    // Set up : I/O
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    // Set up : Input
    int N; cin >> N;

    // Process
    int ans = f(N);

    // Control : Output
    cout << ans << endl;
}

// Helper Functions
int f(int n)
{
    if (n <= 1) return 0;

    int a = n/2;
    int b = n - n/2;

    return a*b + f(a) + f(b);
}

 

 

지적, 조언, 첨언 모두 환영합니다!!!

+ Recent posts