36 lines
757 B
Java
36 lines
757 B
Java
package LanQiaoOJ;
|
||
|
||
import java.math.BigInteger;
|
||
import java.util.Scanner;
|
||
|
||
/*
|
||
* 题目描述
|
||
实现一个算法得到乌托邦树的高度。介绍如下:
|
||
乌托邦树每年经历2个生长周期。每年春天,它的高度都会翻倍。每年夏天,它的高度都会增加1米。
|
||
对于一颗在春天开始时种下的高1米的树,问经过指定周期后,树的高度为多少。*/
|
||
public class 乌托邦树 {
|
||
|
||
public static void main(String[] args) {
|
||
Scanner sc=new Scanner(System.in);
|
||
int t=sc.nextInt();
|
||
//使用高精度
|
||
/*BigInteger h=new BigInteger("1");
|
||
for(int i=0;i<t;i++) {
|
||
if(i%2==0)
|
||
h=h.multiply(new BigInteger("2"));
|
||
else
|
||
h=h.add(new BigInteger("1"));
|
||
|
||
}*/
|
||
int h=1;
|
||
for(int i=0;i<t;i++) {
|
||
if(i%2==0)
|
||
h=h*2;
|
||
else
|
||
h=h+1;
|
||
}
|
||
System.out.print(h);
|
||
}
|
||
|
||
}
|