Solution to a problem UVA11000 [Bee]

Portal

Description [title]

There is a very special bees in Africa. Each year, this is a female bee bee birth a drone, a drone and a female fertility and a bee drones, they will die after giving birth! Now scientists accidentally discovered a magical females this particular species, she is immortal, and can still be a year like any other female bees, like birth once. Scientists want to know how many bees N years later. Please write a program to help them calculate the number and the total number of all the bees N years later drones.

[Enter]

Each input line contains an integer N (≥0), N = -1 to the input end of the (N = -1 procedures do not have to be processed.

[Output] Bee

Each row has two digital outputs, the first number N is the number of years after the drone, the second number is the total number N of bees (two numbers does not exceed 2 ^ 31).

Konjac is not tied to the number of UVA, so do not submit on, but the data in the school oj or over, and a comparison of the details of the problem, pay attention to two topics range does not exceed 2 ^ 31 numbers, so we can play table, O (1) answer, under the laws of their own to push the paper came out, the insurance open long long point.

Code

#include<bits/stdc++.h>
using namespace std;
long long n,ans[100][3];
int main(){
    scanf("%lld",&n);
    ans[0][1]=0;//ans[n][1]为第n年后雄蜂的数量
    ans[0][2]=1;//ans[n][2]为第n年后蜜蜂的总数
    for(int i=1;i<=50;++i){//范围自己跑下看,貌似到40几就够了,50保险点
        ans[i][1]=ans[i-1][2];
        ans[i][2]=ans[i-1][1]+ans[i][1]+1;
    }
    while(n!=-1){
        printf("%lld %lld\n",ans[n][1],ans[n][2]);
        scanf("%lld",&n);
    }
    return 0;
}

Guess you like

Origin www.cnblogs.com/donkey2603089141/p/11414654.html