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;
}