首页 > 其他 > 详细

汉诺塔IV---hdu2077

时间:2016-01-20 09:51:31      阅读:179      评论:0      收藏:0      [点我收藏+]

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2077

 

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define N 25

int main()
{
    int a[N]={0, 2};///汉诺塔三的规律,把最左边的移动到最右边的规律;
    int b[N]={0, 1};///把最左边的移动到中间的规律;
    int c[N]={0, 2};///本题规律;

    int i;

    for(i=2; i<21; i++)
        a[i] = 3*a[i-1]+2;
    for(i=2; i<21; i++)
        b[i] = a[i-1]+1+b[i-1];
    for(i=2; i<21; i++)
        c[i] = 2*b[i-1]+2;

    int T, n;

    scanf("%d", &T);

    while(T--)
    {
        scanf("%d", &n);
        printf("%d\n", c[n]);
    }
    return 0;
}

  

汉诺塔IV---hdu2077

原文:http://www.cnblogs.com/zhengguiping--9876/p/5144105.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!