杭电oj —— 2042

package com.demo2;

import java.util.Scanner;

/*
 * 由于徐老汉没钱,收费员就将他的羊拿走一半,看到老汉泪水涟涟,犹豫了一下,又还给老汉一只。
  *巧合的是,后面每过一个收费站,都是拿走当时羊的一半,然后退还一只,等到老汉到达市场,就只剩下3只羊了。
  *你,当代有良知的青年,能帮忙算一下老汉最初有多少只羊吗?
 */
/*
 * 输入数据第一行是一个整数N,下面由N行组成,每行包含一个整数a(0<a<=30),表示收费站的数量。
 */
public class HDU_oj2042 {
	public static void main(String[] args) {
		Scanner sn = new Scanner(System.in);
		int N = sn.nextInt();
		for(int i = 0;i < N;i++) {
			int a = sn.nextInt();
			compute(a,3);
		}
		sn.close();
	}
	
	public static void compute(int a,int num) {
		for(int i = a;i > 0;i--) {
			num = (num-1) * 2;
		}
		System.out.println(num);
	}

}

猜你喜欢

转载自blog.csdn.net/LiLi_code/article/details/88056586
今日推荐