首页 > 其他 > 详细

HDU 1207

时间:2015-10-31 15:32:26      阅读:264      评论:0      收藏:0      [点我收藏+]

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

 

四柱汉诺塔问题

当 r = (sqrt(8*n+1)-1)/2 时,

存在 count = (n-(r*r-r+2)/2)*(int)pow(2,r)+1 ,此时所需的步骤最少。

 

技术分享
 1 #include<stdio.h>
 2 #include<math.h>
 3 
 4 int main()
 5 {
 6     int n,r;
 7     long long int count;
 8     while(scanf("%d",&n)!=EOF)
 9     {
10         r = (sqrt(8*n+1)-1)/2;
11         count = (n-(r*r-r+2)/2)*(int)pow(2,r)+1;
12         printf("%I64d\n",count);
13     }
14     return 0;
15 }
View Code

 

HDU 1207

原文:http://www.cnblogs.com/52Cassie/p/4925563.html

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