private static final int ONE_YEAR_GROWTH_SUMMER_FACTOR=1
private static final int UTOPIANTREE_INITIALIZE_HEIGHT=1
/**
* compute the hight of utopianTree
* return hight: hight
* parameter src n cycles: 0<= n <=60
* 1 year has 2 cycles :
* spring get double meters height
* summer get 1 meter height
*
* constraints:
* test cases:
* 1<= t <= 10
* cycles :
* 0<= n <= 60
*
* constraint height : initialize height 1 meter
*
* Period Height
0 1
1 2
2 3
3 6
4 7
5 14
* @param srcNumCycle
* @return
*/
public static int utopianTree(int srcNumCycle) {
if(srcNumCycle < 0 || srcNumCycle > 60){
return 0
}
int retVal=srcNumCycle%2
int yearTemp=srcNumCycle/2
int sumTotalHeight=UTOPIANTREE_INITIALIZE_HEIGHT
int plusFactorEvenSpring=0
int plusFactorEvenSummer=ONE_YEAR_GROWTH_SUMMER_FACTOR
int plusFactorOddSpring=0
int plusFactorOddSummer=ONE_YEAR_GROWTH_SUMMER_FACTOR
int plusFactorEven=0
int count=0
while(true){
if(retVal==0){
int countEven=0
while(true){
plusFactorEvenSpring=sumTotalHeight*2
plusFactorEven=plusFactorEvenSpring+plusFactorEvenSummer
sumTotalHeight+=plusFactorEven
countEven++
if(countEven>yearTemp){
break
}
}
}else{
int countOddEven=0
while(true){
plusFactorOddSpring=sumTotalHeight*2
int plusFactorOdd=plusFactorOddSpring+plusFactorOddSummer
sumTotalHeight+=plusFactorOdd
countOddEven++
if(countOddEven>yearTemp){
break
}
}
plusFactorOddSpring=sumTotalHeight*2
sumTotalHeight+=plusFactorOddSpring
}
int yearCount=0
if(retVal==0){
yearCount=yearTemp
}else{
yearCount=yearTemp+1
}
count++
if(count>yearCount){
break
}
}
return sumTotalHeight
}