zoukankan      html  css  js  c++  java
  • HDU 5366 The mook jong

    题目链接:

    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
    ",f[n]);
    14     }
    15     return 0;
    16 }
     
     
  • 相关阅读:
    上学路线 (Standard IO)
    舞台设置 (Standard IO)
    Circle (Standard IO)
    Number (Standard IO)
    Gift (Standard IO)
    圆周舞蹈 (Standard IO)
    竞赛排名 (Standard IO)
    奶牛排队 (Standard IO)
    奶牛晒衣服 (Standard IO)
    神奇的风 (Standard IO)
  • 原文地址:https://www.cnblogs.com/wenzhixin/p/7518211.html
Copyright © 2011-2022 走看看