码迷,mamicode.com
首页 > 编程语言 > 详细

题目1458:汉诺塔III(不一样的汉诺塔递归算法)

时间:2017-04-23 15:56:11      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:c++   result   ace   code   nbsp   eof   copyright   ++   blank   

题目链接:http://ac.jobdu.com/problem.php?pid=1458

详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus

参考代码:

//
//  1458 汉诺塔III.cpp
//  Jobdu
//
//  Created by PengFei_Zheng on 23/04/2017.
//  Copyright © 2017 PengFei_Zheng. All rights reserved.
//
 
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <cmath>
 
using namespace std;
int ans = 0;
 
long long hanoi(int n){
    if(n==0) return 0;
    if(n==1) return 2;
    return 3*hanoi(n-1)+2;
}
 
int n;
 
int main(){
    while(scanf("%d",&n)!=EOF){
        printf("%lld\n",hanoi(n));
    }
}
/**************************************************************
    Problem: 1458
    User: zpfbuaa
    Language: C++
    Result: Accepted
    Time:0 ms
    Memory:1520 kb
****************************************************************/

 

题目1458:汉诺塔III(不一样的汉诺塔递归算法)

标签:c++   result   ace   code   nbsp   eof   copyright   ++   blank   

原文地址:http://www.cnblogs.com/zpfbuaa/p/6752631.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!