递归及递推系列之 汉诺塔III hdoj 2064
2014-08-13 11:29
253 查看
/*
汉诺塔III
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 9346 Accepted Submission(s): 4192
Problem Description
约19世纪末,在欧州的商店中出售一种智力玩具,在一块铜板上有三根杆,最左边的杆上自上而下、由小到大顺序串着由64个圆盘构成的塔。目的是将最左边杆上的盘全部移到右边的杆上,条件是一次只能移动一个盘,且不允许大盘放在小盘的上面。
现在我们改变游戏的玩法,不允许直接从最左(右)边移到最右(左)边(每次移动一定是移到中间杆或从中间移出),也不允许大盘放到下盘的上面。
Daisy已经做过原来的汉诺塔问题和汉诺塔II,但碰到这个问题时,她想了很久都不能解决,现在请你帮助她。现在有N个圆盘,她至少多少次移动才能把这些圆盘从最左边移到最右边?
Input
包含多组数据,每次输入一个N值(1<=N=35)。
Output
对于每组数据,输出移动最小的次数。
Sample Input
1
3
12
Sample Output
2
26
531440
Author
Rabbit
Source
RPG专场练习赛
*/
/*
人家代码:
#include<stdio.h>
#include<stdlib.h>
__int64 f(int a,__int64 b)
{
if(a==1)
{
printf("%I64d\n",b-1);
}
else
f(a-1,3*b);
}
int main()
{
int n;
while(~scanf("%d",&n))
{
f(n,3);
}
return 0;
}
*/
咱家代码:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define M 100
__int64 a[M];
int main()
{
int i,j;
memset(a,0,sizeof(a));
for(i=1;i<=35;i++)
{
a[i]=1;
for(j=i;j>0;j--)//每次移动一个就需要三次;
{
a[i]*=3;
}
}
int n;
while(~scanf("%d",&n))
{
printf("%I64d\n",a
-1);
}
return 0;
}
汉诺塔III
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 9346 Accepted Submission(s): 4192
Problem Description
约19世纪末,在欧州的商店中出售一种智力玩具,在一块铜板上有三根杆,最左边的杆上自上而下、由小到大顺序串着由64个圆盘构成的塔。目的是将最左边杆上的盘全部移到右边的杆上,条件是一次只能移动一个盘,且不允许大盘放在小盘的上面。
现在我们改变游戏的玩法,不允许直接从最左(右)边移到最右(左)边(每次移动一定是移到中间杆或从中间移出),也不允许大盘放到下盘的上面。
Daisy已经做过原来的汉诺塔问题和汉诺塔II,但碰到这个问题时,她想了很久都不能解决,现在请你帮助她。现在有N个圆盘,她至少多少次移动才能把这些圆盘从最左边移到最右边?
Input
包含多组数据,每次输入一个N值(1<=N=35)。
Output
对于每组数据,输出移动最小的次数。
Sample Input
1
3
12
Sample Output
2
26
531440
Author
Rabbit
Source
RPG专场练习赛
*/
/*
人家代码:
#include<stdio.h>
#include<stdlib.h>
__int64 f(int a,__int64 b)
{
if(a==1)
{
printf("%I64d\n",b-1);
}
else
f(a-1,3*b);
}
int main()
{
int n;
while(~scanf("%d",&n))
{
f(n,3);
}
return 0;
}
*/
咱家代码:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define M 100
__int64 a[M];
int main()
{
int i,j;
memset(a,0,sizeof(a));
for(i=1;i<=35;i++)
{
a[i]=1;
for(j=i;j>0;j--)//每次移动一个就需要三次;
{
a[i]*=3;
}
}
int n;
while(~scanf("%d",&n))
{
printf("%I64d\n",a
-1);
}
return 0;
}
相关文章推荐
- HDU 2064 (递推) 汉诺塔III
- HDU 2064 汉诺塔III【递推】
- 递归及递推问题系列之 不容易系列之(3)—— LELE的RPG难题 hdoj 2048
- HDU-2064 汉诺塔III 递推题
- 递推递归练习 D 汉诺塔系列1
- 递归及递推问题系列之 Number Sequence hdoj 1005
- (Java实现)HDOJ 2064 汉诺塔III && 2077 汉诺塔IV
- hdu 2064汉诺塔III 递推
- HDOJ2064_汉诺塔III
- 递推递归练习D - 汉诺塔系列1
- 递归递推练习―D―汉诺塔系列1
- HDOJ 汉诺塔系列(递推分析)
- 递归及递推问题系列之 Tiling_easy version hdoj 2501
- 递归递推练习 D 汉诺塔系列1
- HDU 2064 汉诺塔III(递归)
- hdoj 2064 汉诺塔III
- HDU 2064 汉诺塔III (递推)
- HDU 2064 汉诺塔III (递归)
- 递推递归练习D - 汉诺塔系列1
- HDOJ 2064 汉诺塔III