The Utopian tree goes through 2 cycles of growth every year. The first growth cycle of the tree occurs during the monsoon, when it doubles in height. The second growth cycle of the tree occurs during the summer, when its height increases by 1 meter.
Now, a new Utopian tree sapling is planted at the onset of the monsoon.
Its height is 1 meter. Can you find the height of the tree after N growth cycles?

Input Format
The first line contains an integer, T, the number of test cases.
T lines follow. Each line contains an integer, N, that denotes the number of cycles for that test case.

Constraints
1 <= T <= 10
0 <= N <= 60

Output Format
For each test case, print the height of the Utopian tree after N cycles.


题解:

 import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*; public class Solution { static int Utopian_Tree(int N) {
if(N == 0)
return 1;
if(N == 1)
return 2;
if(N%2 == 0)
return (int)Math.pow(2, N/2+1)-1;
return (int)Math.pow(2, N/2+2)-2;
} public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t;
t = in.nextInt();
for(int i = 0;i < t;i++){
int n;
n = in.nextInt();
System.out.println(Utopian_Tree(n));
}
}
}

【HackerRank】Utopian tree的更多相关文章

  1. 【BZOJ】2631: tree LCT

    [题意]给定n个点的树,每个点初始权值为1,m次操作:1.x到y的点加值,2.断一条边并连一条边,保证仍是树,3.x到y的点乘值,4.x到y的点权值和取模.n,m<=10^5. [算法]Link ...

  2. 【BZOJ2212】[Poi2011]Tree Rotations 线段树合并

    [BZOJ2212][Poi2011]Tree Rotations Description Byteasar the gardener is growing a rare tree called Ro ...

  3. 【题解】Digit Tree

    [题解]Digit Tree CodeForces - 716E 呵呵以为是数据结构题然后是淀粉质还行... 题目就是给你一颗有边权的树,问你有多少路径,把路径上的数字顺次写出来,是\(m\)的倍数. ...

  4. 【题解】[P4178 Tree]

    [题解]P4178 Tree 一道点分治模板好题 不知道是不是我见到的题目太少了,为什么这种题目都是暴力开值域的桶QAQ?? 问点对,考虑点分治吧.直接用值域树状数组开下来,统计的时候直接往树状数组里 ...

  5. 【总结】Link-Cut Tree

    这是一篇关于LCT的总结 加删边的好朋友--Link Cut Tree Link-Cut Tree,LCT的全称 可以说是从树剖引出的问题 树剖可以解决静态的修改或查询树的链上信息:那如果图会不断改变 ...

  6. 【BZOJ】1468: Tree(POJ1741) 点分治

    [题意]给定带边权树,求两点距离<=k的点对数.n<=40000. [算法]点分治 [题解]对于一个区域,选择其重心x作为根,则划分出来的每棵子树都是子区域,可以证明至多划分log n次( ...

  7. 【HackerRank】Cut the tree

    题目链接:Cut the tree 题解:题目要求求一条边,去掉这条边后得到的两棵树的节点和差的绝对值最小. 暴力求解会超时. 如果我们可以求出以每个节点为根的子树的节点之和,那么当我们去掉一条边(a ...

  8. 【题解】【BT】【Leetcode】Binary Tree Preorder/Inorder/Postorder (Iterative Solution)

    [Inorder Traversal] Given a binary tree, return the inorder traversal of its nodes' values. For exam ...

  9. 【Leetcode】【Easy】Binary Tree Level Order Traversal II

    Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left ...

随机推荐

  1. JavaScript 框架(库)

    JavaScript 高级程序设计(特别是对浏览器差异的复杂处理),通常很困难也很耗时. 为了应对这些调整,许多的 JavaScript (helper) 库应运而生. 这些 JavaScript 库 ...

  2. poj 1548(最小路径覆盖)

    题目链接:http://poj.org/problem?id=1548 思路:最小路径覆盖是很容易想到的(本题就是求最小的路径条数覆盖所有的点),关键是如何建图,其实也不难想到,对于当前点,如果后面的 ...

  3. 5-1、easyUI-菜单与按钮(上节问题与解决)

    首先把上节的代码copy过来,如下: <html> <head> <meta http-equiv="Content-Type" content=&q ...

  4. Python中MRO

    MRO(方法解析顺序) 当有多重继承时,基于“从左到右,深度优先原则”: class CommonBase(): def Method(self): print('CommonBase') class ...

  5. 使用Nexus管理Maven仓库时,上传带依赖的第三方jar

    总所周知,使用Maven构建非常方便.在企业中使用Nexus创建私服来管理Maven时,需要上传很多没有开放源码的第三方Jar包.本文将讲述当第三方Jar包有很多并且互相有依赖时如何上传. 核心操作 ...

  6. jQuery DOM 元素方法(get)

    jQuery DOM 元素方法 1..get() 获得由选择器指定的 DOM 元素. $(selector).get(index)index 可选.规定获取哪个匹配元素(通过 index 编号). 实 ...

  7. SpringBoot整合Dubbo报错: java.lang.ClassCastException

    com.alibaba.dubbo.rpc.RpcException: Failed to invoke remote proxy method queryGoodsLimitPage to regi ...

  8. 安装git和配置

     首先更新系统 yum  -y update  安装依赖的包 yum -y install curl-devel expat-devel gettext-devel openssl-devel zli ...

  9. 在Nuxt中使用 Highcharts

    npm进行highchars的导入,导入完成后就可以进行highchars的可视化组件开发了 npm install highcharts --save 1.components目录下新建一个char ...

  10. MySQL将语句写入到binlog二进制日志中

    由于二进制日志是公共资源,所有线程都要写二进制日志,所以一定要避免两个线程同时更新二进制日志.因此,在事件组写二进制日志时,二进制日志将获得一个互斥锁LOCK_log,然后在事件组写完后释放,由于服务 ...