hd 2077 漢諾塔IV

<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
lcy   |   We have carefully selected several similar problems for you:  1207 2175 2184 1997 2511 

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章