日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

2020牛客国庆集训派对day2 VIRUS OUTBREAK

發(fā)布時間:2023/12/3 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 2020牛客国庆集训派对day2 VIRUS OUTBREAK 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

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

題解:

直接看樣例就不難看出是求斐波那契數(shù)列,再一看數(shù)據(jù)范圍,果然是大數(shù)的斐波那契數(shù)列,我拿出珍藏的java版的斐波那契數(shù)列,java對寫大數(shù)加減等這方面有得天獨厚的優(yōu)勢
但是爺就想用c++來寫咋辦?
要知道300的斐波那契數(shù)列是222232244629420445529739893461909967206666939096499764990979600
longlong也存不下,那怎么辦?我們就用數(shù)組來存數(shù),就是一位一位的存,然后我們手寫模擬加法過程,前兩位相加等于第三位,記得考慮進位情況

代碼:

#include <stdio.h> #include <string.h> #include<bits/stdc++.h> using namespace std; int a[1005][1005]; int main() {int T;int n;while(cin>>n){if(n==-1)break;int c;int d=0;memset(a,0,sizeof(a));a[1][0]=1;a[2][0]=1;//第一個和第二個數(shù)要先保存下來 for(int i=3;i<=n;i++)//從第三個數(shù)開始都是等于前兩個數(shù)的和 {c=0;//保存余數(shù) for(int j=0;j<=d;j++){a[i][j]=a[i-1][j]+a[i-2][j]+c;//計算結(jié)果 c=a[i][j]/10;//將其他的數(shù)進位 a[i][j]%=10;//將大于10的數(shù)要余數(shù) }while(c!=0)//最后一位要是大于10,需要進位,并且最高位也需要加1! {a[i][++d]=c%10;c/=10;}}printf("Hour: %d: ",n);for(int i=d;i>=0;i--)//輸出需要求的數(shù)的所有的位所有的值! {printf("%d",a[n][i]);}printf(" cow(s) affected\n");}return 0; }

總結(jié)

以上是生活随笔為你收集整理的2020牛客国庆集训派对day2 VIRUS OUTBREAK的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。