Last active
June 29, 2016 21:45
-
-
Save bowbowbow/1e626b1f050ac682d80faf08f0d3c623 to your computer and use it in GitHub Desktop.
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 <iostream> | |
#include <cstdio> | |
#include <algorithm> | |
using namespace std; | |
#define ull unsigned long long | |
/* | |
규칙을 K번 적용해서 숫자 N을 만들 수 있는 수 중 | |
최댓값(type이 1일 때), 최솟값(type이 0일 때)을 구하는 함수 | |
*/ | |
ull back(ull N, int K, bool type){ | |
if(K == 0) | |
return N; | |
//규칙 : 2배 나누기 거꾸로 | |
ull res = back(2*N, K-1, type); | |
//규칙 : 3배 하고 1 더하기 거꾸로 (거꾸로 가려면 나누어떨어야 하고 홀수여야 함) | |
if( ( (N-1) >= 6 ) && ( (N-1)%3 ==0 ) && ( ( (N-1)/3)%2 == 1 ) ){ | |
if(type) | |
res = max(res, back((N-1)/3, K-1, type)); | |
else | |
res = min(res, back((N-1)/3, K-1, type)); | |
} | |
return res; | |
} | |
int main(){ | |
int T; | |
setbuf(stdout, NULL); | |
cin >> T; | |
for(int t = 1 ; t <= T ; t++){ | |
int K; | |
cin >> K; | |
printf("Case #%d\n%llu %llu\n", t, back(1, K, 0), back(1, K, 1)); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment