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

题解:

直接看样例就不难看出是求斐波那契数列,再一看数据范围,果然是大数的斐波那契数列,我拿出珍藏的java版的斐波那契数列,java对写大数加减等这方面有得天独厚的优势
但是爷就想用c++来写咋办?
要知道300的斐波那契数列是222232244629420445529739893461909967206666939096499764990979600
longlong也存不下,那怎么办?我们就用数组来存数,就是一位一位的存,然后我们手写模拟加法过程,前两位相加等于第三位,记得考虑进位情况

代码:

#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;//第一个和第二个数要先保存下来 for(int i=3;i<=n;i++)//从第三个数开始都是等于前两个数的和 {c=0;//保存余数 for(int j=0;j<=d;j++){a[i][j]=a[i-1][j]+a[i-2][j]+c;//计算结果 c=a[i][j]/10;//将其他的数进位 a[i][j]%=10;//将大于10的数要余数 }while(c!=0)//最后一位要是大于10,需要进位,并且最高位也需要加1! {a[i][++d]=c%10;c/=10;}}printf("Hour: %d: ",n);for(int i=d;i>=0;i--)//输出需要求的数的所有的位所有的值! {printf("%d",a[n][i]);}printf(" cow(s) affected\n");}return 0;
}

2020牛客国庆集训派对day2 VIRUS OUTBREAK相关推荐

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

    2020牛客国庆集训派对day2 补题J:VIRUS OUTBREAK 题目描述 The State Veterinary Services Department recently reported ...

  2. 2020牛客国庆集训派对day2 H-STROOP EFFECT(英语题)

    2020牛客国庆集训派对day2 H-STROOP EFFECT(英语题) 题目 https://ac.nowcoder.com/acm/contest/7818/H 题意 这题目真的太难读懂了,赛后 ...

  3. 2020牛客国庆集训派对day2 F题 Java大数处理

    题目: 链接:https://ac.nowcoder.com/acm/contest/16913/F 来源:牛客网 The following code snippet calculates the ...

  4. 2020牛客国庆集训派对day2 AKU NEGARAKU

    来源:牛客网: 题目描述 1st Academy is an international leadership training academy based in Kuala Lumpur. Ever ...

  5. 2020牛客国庆集训派对day2(A,C,D,E,F,G,H,J,)

    A.AKU NEGARAKU 约瑟夫环裸题 AC代码 #include<iostream> #include<stdio.h> using namespace std; #de ...

  6. 2020牛客国庆集训派对day2 MATRIX MULTIPLICATION CALCULATOR

    MATRIX MULTIPLICATION CALCULATOR 题意: 求两矩阵相乘 题解: 应该都学过把...矩阵相乘 矩阵相乘的前提是两个矩阵的列等于另一个矩阵的行 也就是cij=∑aik*bk ...

  7. 2019牛客国庆集训派对day2 K 2018(容斥)

    链接:https://ac.nowcoder.com/acm/contest/1107/K 来源:2019牛客国庆集训派对day2 题目描述   Given a, b, c, d, find out ...

  8. 2020牛客国庆集训派对day3 I.Rooted Tree(哈代-拉马努金拆分数列)

    2020牛客国庆集训派对day3 I.Rooted Tree(哈代-拉马努金拆分数列) 题目 https://ac.nowcoder.com/acm/contest/7830/I 题意 给你n个点,问 ...

  9. 2020牛客国庆集训派对day8 G-Shuffle Cards(扩展STL容器,rope可持久化平衡树)

    2020牛客国庆集训派对day8 G-Shuffle Cards(扩展STL容器,rope可持久化平衡树) 题目 https://ac.nowcoder.com/acm/contest/7865/G ...

最新文章

  1. 江苏省计算机一级考试知识点总结,江苏省计算机一级考试注意要点1
  2. python教程实例-python 类和实例 - 刘江的python教程
  3. Aix iostat命令解析
  4. 一文搞定JS事件基础与进阶
  5. MFC ListCtrl和IP控件的使用杂记
  6. verilog中值滤波算法实现及仿真
  7. javascript --- 手写Promise、快排、冒泡、单例模式+观察者模式
  8. AJAX全套(JSONP、CORS)
  9. QApplication
  10. odata数据绑定_如何使用用于SQL Server集成服务的OData源将数据导入SQL Server数据库
  11. 想加入Google AI中国团队?你可能得飞去美国面试
  12. 密码库LibTomCrypt学习记录——(1.0)分组密码算法——概述
  13. 水电缴费系统php源码_php水电费缴费管理系统
  14. 一种实用的BOOST电路_UC3842升压设计
  15. 人机交互期末复习笔记
  16. 多线程 java实验心得_java多线程编程体会
  17. matplotlib用Times New Roman且不加粗
  18. hive基本用法及细节记录
  19. 2022-2028年中国民营医疗行业市场运营态势及投资战略规划报告
  20. MySQL 的几种碎片整理方案总结(解决delete大量数据后空间不释放的问题)

热门文章

  1. bitmap 转byte[]后读取_闲谈redis的bitmap
  2. matlab绘制二元一次函数图像_【八上数学】 一次函数必考知识点(下)
  3. 服务器精益改善系列,精益生产改善的内容是什么?
  4. android gdb 远程调试工具,Android下用gdb远程调试办法
  5. java spring 单例模式,spring中的单例模式
  6. win10+tomcat+php+配置环境变量配置,Win10系统Tomcat环境变量配置方法
  7. java中如何运行小程序_一起学java(一)——运行第一个小程序
  8. MYSQL数据库表大小计算,计算mysql数据库数据表的大小,不精确,只是大略的数据...
  9. linux mysql帮助文档,在 Linux 上安装 MySQL
  10. html云雾效果,PS中怎么做像这样的云雾效果?(有图)?