11.27 Yu Gong family how many people && Zombie Wars Gatlin

today's. Two questions a day. All kind of interesting (loud bb)

first question:

topic

I read less, you have to help me

Description

This is a simple question of title, just your math test only. I've always been curious about how many people in the end a foolish old man. Well, it said Tuesday Mao learned you will help me. Family assumption that the Foolish Old Man every person's life is spent :( when he look back ... a joke, please ignore ) for the first 20 years of growth and development as well as digging the first 21 years (can be understood as 21 age) began to give birth to a child (yearly self , self-willed, not his wife, the whole birth to a boy, and do not consider death ), of course, dig up the mountain. We default Foolish Old Man 11 years old when for the first year (the first 21 years of the Foolish Old Man gave birth to their first child), seeking the Foolish Old Man of the Year NN family (wife Yu Gong family do not need, do not think too much about) how many people.

Input

A plurality of test data sets, each representing one line, comprising a number N (0 <N <= 60) N (0 <N <= 60), N for the N-th years.

Output

For each test, the output integer M, M is the number of Yu Gong family.

Sample Input 1

1
21
41

Sample Output 1

1
2
23


Problem-solving

Tianzuo chiefs talked about the issue seem to remember a raw rabbit (similar to a Fibonacci number)
from the Internet to find a related article: I am portal T ^ T article
21 days adult can have children. So, the Foolish Old Man descendants growth 20 years can have children
so defined here as the n-th day of the Foolish Old Man family a total of f (n) person, then the previous day is f (n-1) individuals, an increase in the number yesterday to today then, f (n-1 + 21 ) = f (n-20).
Such a result Release equation: F (n-) = F (n--. 1) + F (n--20 is)
apparent recursive algorithm to compute it.

#include<stdio.h>
int f(int n)
{
    if(n>=0&&n<21)
    {
        return 1;
    }
    else if(n>=21)
    {
        return f(n-1)+f(n-20);
    }
}
int main()
{
    int n=0;
    int m=0;
    while(scanf("%d",&n)!=EOF)
    {
        m=f(n);
        printf("%d\n",m);
    }
    return 0;
}

The second question

topic

Gatlin Zombies

Description

And now to play Resident Evil hair sister school of the time, the problem is very simple. Now there is an automatic Gatling gun, which emits a second bullet, bullet flying speed is V0. In front of it there is L-meter space, you can assume that a machine gun point. There is now a zombie struck, he walked to the V1 uniform Gatling gun to speed. Gatlin was hit by a bullet zombies n times before gg, zombies come after Gatling gun position, it will be attacked with acid, just 2s will be able to destroy Gatlin. Q: powerful Gatling gun can hold this space it?

Input

Input comprising a plurality of sets of data, each comprising four numbers L, V0, V1, n. To ensure that all the data within the range of type int.

Output

If Gatlin can kill zombies, please output "YES", otherwise a "NO".

Sample Input 1

657 62 46 46
771 89 7 2

Sample Output 1

NO
YES

Hint

To simplify the situation, the situation does not appear zombies and Gatling die (death together) of


Problem-solving

Speed Gatling firing bullets is a pretext!
Gatlin launch a second bullet. In other words, how many seconds the zombie walk, he most (probably because there are zombies halfway dead) by the number of rounds of ammunition. Then the time = number of bullets.
There is such a formula: n1 = T = L / V1 + 2
and then determines the magnitude relation between n1 and n are like!

#include<stdio.h>
int main()
{
    int l,v0,v1,n;
    double t;
    while(scanf("%d %d %d %d",&l,&v0,&v1,&n)!=EOF)
    {
        t=l/v1+2;
        if(t>=n)
        {
            printf("YES\n");
        }
        else if(t<n)
        {
            printf("NO\n");
        }
    }
    return 0;
}


Guess you like

Origin blog.csdn.net/qq_42906486/article/details/84564192