본문 바로가기

Computer Science/Algorithm

[Algorithm] Utopian Tree

Utopian Tree



[문제]

Utopian Tree는 1년에 2Cycle을 통해 성장한다. 

봄에 2배로 자란다. 

여름에 1m 자란다.


현재 Utopian Tree의 키는 1m이다. 

N Cycle 후의 키는 몇인가 ? 



[Input Format]

첫째줄에 총 Test Cases의 수, T

T의 라인들은 각각 테스트케이스의 cycle 수를 가리키는 N을 가진다.


[Constraint]

1<= T<=10

0<=N<=60




[Solve]

Cycle이 2단계를 반복한다. 

1,3,5,7cycle에는 2배, 

2,4,6,8,10 cycle에는 1m가 자란다. 


즉, 

2n -> 1m

2n+1 -> 2배 


이를 코드로 나타내면 다음과 같다. 


if(cycle % 2 == 0 )

1m 성장 

else 

2배 성장 




   



'Computer Science > Algorithm' 카테고리의 다른 글

[Algorithm] Sherlock and Array  (0) 2016.04.11
[Algorithm] Snakes and Ladders: The Quickest Way Up  (0) 2016.04.08
[Algorithm] Grid Challenge  (0) 2016.03.28
[Algorithm] Maximise Sum  (0) 2016.03.25
Algorithm 진행 계획  (0) 2016.03.16