<h1 style="COLOR: #1a5cc8">汉诺塔IV</h1><span size="+0"><strong><span style="font-family:Arial;font-size:12px;color:green;FONT-WEIGHT: bold">Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3809 Accepted Submission(s): 2844
</span></strong></span>
<div class="panel_title" align="left">Problem Description</div><div class="panel_content">还记得汉诺塔III吗?他的规则是这样的:不允许直接从最左(右)边移到最右(左)边(每次移动一定是移到中间杆或从中间移出),也不允许大盘放到小盘的上面。xhd在想如果我们允许最大的盘子放到最上面会怎么样呢?(只允许最大的放在最上面)当然最后需要的结果是盘子从小到大排在最右边。
</div><div class="panel_bottom"> </div>
<div class="panel_title" align="left">Input</div><div class="panel_content">输入数据的第一行是一个数据T,表示有T组数据。
每组数据有一个正整数n(1 <= n <= 20),表示有n个盘子。
</div><div class="panel_bottom"> </div>
<div class="panel_title" align="left">Output</div><div class="panel_content">对于每组输入数据,最少需要的摆放次数。
</div><div class="panel_bottom"> </div>
<div class="panel_title" align="left">Sample Input</div><div class="panel_content"><pre><div style="FONT-FAMILY: Courier New,Courier,monospace">2
1
10</div>
Sample Output
2 19684
Author
xhd
Source
Recommend
#include<stdio.h>
#include<math.h>
int main()
{
int n,t;
__int64 s;
while(scanf("%d",&t)!=EOF)
{
while(t--)
{
scanf("%d",&n);
s=pow(3,n-1);
printf("%I64d\n",s+1);
}
}
return 0;
}