2020牛客国庆集训派对day2 补题J

2020牛客国庆集训派对day2
补题J:VIRUS OUTBREAK
题目描述
The State Veterinary Services Department recently reported an outbreak of a newly found cow disease. All cows found to have affected by the disease have since euthanized because of the risk to the industry. Number of affected cows increased to 21, 34 and reached 55 after eight, nine and ten hours respectively.
You have been assigned by the authority to study the pattern of the outbreak and develop a program to predict the next number of affected cows so that the authorities could prepare and act accordingly.
输入描述:
Input will consist of a series of positive integer numbers no greater than 490 each on a separate line represent the hours. The input process will be terminated by a line containing -1.
输出描述:
For each input value, the output contains a line in the format: \text { Hour } \mathbf{X}: \mathbf{Y} \text { cow(s) affected } Hour X:Y cow(s) affected , where \mathbf{X}X is the hour, and \mathbf{Y}Y is the total affected cows that need to be euthanized based on the hour given by \mathbf{X}X.
示例1
输入
复制
1
4
6
11
-1
输出
复制
Hour: 1: 1 cow(s) affected
Hour: 4: 3 cow(s) affected
Hour: 6: 8 cow(s) affected
Hour: 11: 89 cow(s) affected
本题是数据范围非常大的斐波那契数列
所以用数组来存数
代码:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<vector>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<sstream>
#include<memory>
#include<functional>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a));
#define ll long long int
const int INF = 0x3f3f3f3f;
int js[1005][1005],d[500];d数组用来计每个
int main()
{
    js[1][0]=1;
    js[2][0]=1;
    for(int i=3;i<=490;++i)//将从0到第490个都求出
    {
        d[i]=d[i-1];
        int c=0;//c用来保存余数
        for(int j=0;j<=d[i];++j)
        {
            js[i][j]=js[i-1][j]+js[i-2][j]+c;
            c=js[i][j]/10;
            js[i][j]%=10;
        }//d是最高位
        while(c!=0)//若最后一位大于10需要进位,且最高位要加1
        {
            js[i][++d[i]]=c%10;
            c/=10;
        }
    }
    for(int i=1;;++i)
    {
        int n;
        scanf("%d",&n);问到几就说几
        if(n==-1)
            return 0;
        printf("Hour: %d: ",n);
        for(int j=d[n];j>=0;j--)
        {
            printf("%d",js[n][j]);
        }
        printf(" cow(s) affected\n");
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值