汉诺塔 复习

发布时间:2019年08月29日 阅读:283 次

https://blog.csdn.net/Cherishlife_/article/details/84454614

https://blog.csdn.net/dreamzuora/article/details/53150898

https://blog.csdn.net/dreamzuora/article/details/53150853

汉诺塔基本题

http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/1200.html

#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int head[9999],n;
const int inf = 0x3f3f3f3f;
void dfs(int m,char a,char b,char c){

    if(m==1){
        printf("Move disk %d from %c to %c\n",m,a,c);
        return;
    }
    dfs(m-1,a,c,b);
    printf("Move disk %d from %c to %c\n",m,a,c);
    dfs(m-1,b,a,c);
}
int main()
{


    cin>>n;
    dfs(n,'A','B','C');
    return 0;
}

汉诺塔系列1

http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/2064.html

3^n

汉诺塔系列2

http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/2066.html

2^(n-m)

Tag:
相关文章

发表评论: