LanQiaoTestCodes/乌托邦树.java

36 lines
757 B
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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);
}
}