zoukankan      html  css  js  c++  java
  • HDU-2018

    母牛的故事

    Problem Description
    有一头母牛,它每年年初生一头小母牛。每头小母牛从第四个年头开始,每年年初也生一头小母牛。请编程实现在第n年的时候,共有多少头母牛?
     

    Input

    输入数据由多个测试实例组成,每个测试实例占一行,包括一个整数n(0<n<55),n的含义如题目中描述。
    n=0表示输入数据的结束,不做处理。
     
    Output
    对于每个测试实例,输出在第n年的时候母牛的数量。
    每个输出占一行。
     
    Sample Input
    2 4 5 0
     
    Sample Output
    2 4 6
     
    s[n]=s[n-1]+s[n-3];
     1 #include<stdio.h>
     2 #include<stdlib.h>
     3 #include<math.h>
     4 #include<string.h>
     5 int main()
     6 {
     7     int n;
     8     int count[100];
     9     int i;
    10     int c;
    11     count[1]=1;
    12     count[2]=2;
    13     count[3]=3;
    14     while (1)
    15     {
    16         scanf("%d",&n);
    17         c=n;
    18         if (0==n) break;
    19         if (n>3)
    20         {
    21             i=3;
    22             n-=3;
    23             while (n--)
    24             {
    25                 i++;
    26                 count[i]=count[i-1]+count[i-3];
    27             }
    28         }
    29         printf("%d
    ",count[c]);
    30     }
    31     return 0;
    32 }
  • 相关阅读:
    去掉滚动条
    一些input用法
    jquery-ui datepicker
    js修改样式
    js时间
    跳转到页面的某个anchor
    事件传递
    flex对象.show()的时候display变成block
    html中传递信息
    button disable and enable
  • 原文地址:https://www.cnblogs.com/leiyuxiang/p/3491238.html
Copyright © 2011-2022 走看看