码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 5366 The mook jong

时间:2017-09-14 00:37:06      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:保险   ons   lin   use   jpg   直接   line   put   any   

题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=5366

Problem Description
![](../../data/images/C613-1001-1.jpg)

ZJiaQ want to become a strong man, so he decided to play the mook jong。ZJiaQ want to put some mook jongs in his backyard. His backyard consist of n bricks that is 1*1,so it is 1*n。ZJiaQ want to put a mook jong in a brick. because of the hands of the mook jong, the distance of two mook jongs should be equal or more than 2 bricks. Now ZJiaQ want to know how many ways can ZJiaQ put mook jongs legally(at least one mook jong).
 
Input
There ar multiply cases. For each case, there is a single integer n( 1 < = n < = 60)
 
Output
Print the ways in a single line for each case.
 
Sample Input
1
2
3
4
5
6
Sample Output
1
2
3
5
8
12
题意描述:
输入砖数n( 1 < = n < = 60)
计算并输出有多少种合法的放器材的方法(至少有一个器材)
解题思路:
首先想到的是数据范围是1到60,打表解决。
具体打表过程中刚开始想的是有一个公式计算,就一直在总结那个公式,花费了好多时间,其实这种题直接列出来找规律递推即可。
另外,最好将数组定义为long long不容易溢出,也更为保险。
AC代码:
 1 #include<stdio.h>
 2 int main()
 3 {
 4     int n,sum,i;
 5     long long f[60];//int类型55以上出现错误,改为long long 
 6     f[1]=1;
 7     f[2]=2;
 8     f[3]=3;
 9     for(i=4;i<=60;i++)
10         f[i]=f[i-1]+f[i-3]+1;
11     while(scanf("%d",&n) != EOF)
12     {
13         printf("%lld\n",f[n]);
14     }
15     return 0;
16 }

 

 
 

HDU 5366 The mook jong

标签:保险   ons   lin   use   jpg   直接   line   put   any   

原文地址:http://www.cnblogs.com/wenzhixin/p/7518211.html

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