# 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);
}
지적, 조언, 첨언 모두 환영합니다!!!
'Problem Solving > 백준' 카테고리의 다른 글
| [ Problem Solving :: 백준 ] 11558 / The Game of Death (0) | 2021.11.16 |
|---|---|
| [ Problem Solving :: 백준 ] 2698 / 인접한 비트의 개수 (0) | 2021.11.16 |
| [ Problem Solving :: 백준 ] 2616 / 소형기관차 (0) | 2021.11.16 |
| [ Problem Solving :: 백준 ] 2602 / 돌다리 건너기 (0) | 2021.11.16 |
| [ Problem Solving :: 백준 ] 4386 / 별자리 만들기 (0) | 2021.11.15 |