HDUOJ-----Computer Transformation
Computer Transformation
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4842 Accepted Submission(s): 1769
Problem Description
A sequence consisting of one digit, the number 1 is initially written into a computer. At each successive time step, the computer simultaneously tranforms each digit 0 into the sequence 1 0 and each digit 1 into the sequence 0 1. So, after the first time step, the sequence 0 1 is obtained; after the second, the sequence 1 0 0 1, after the third, the sequence 0 1 1 0 1 0 0 1 and so on. How many pairs of consequitive zeroes will appear in the sequence after n steps?
Input
Every input line contains one natural number n (0 < n ≤1000).
Output
For each input n print the number of consecutive zeroes pairs that will appear in the sequence after n steps.
Sample Input
2
3
Sample Output
1
1
做这道题,纯粹是一道大数的题,当然你需要推导出这个公式f[n]=f[n-1]+2*f[n-2];
1 #include<cstdio>
2 const int maxn=1000;
3 int arr[maxn+1][305]={0};
4 int len=1;
5 void LargeNum()
6 {
7 arr[1][0]=1;
8 for(int i=2;i<=maxn;i++)
9 {
10 int c=0;
11 for(int j=0;j<len;j++)
12 {
13 arr[i][j]+=arr[i-1][j]+2*arr[i-2][j]+c;
14 if(arr[i][len-1]>9)
15 len++;
16 c=arr[i][j]/10;
17 arr[i][j]%=10;
18 }
19 }
20
21 }
22 int main( void )
23 {
24 int n,i;
25 LargeNum();
26 while(scanf("%d",&n)==1)
27 {
28 if(n==1)puts("0");
29 else
30 {
31 for(i=len;arr[n-1][i]==0;i--);
32 for(int j=i;j>=0;j--)
33 printf("%d",arr[n-1][j]);
34 puts("");
35 }
36 }
37 return 0;
38 }
- Spring Cloud中Hystrix 线程隔离导致ThreadLocal数据丢失
- 内网穿透工具-ittun
- Elastic-Job-Spring-Boot-Starter简化你的任务配置
- Spring Boot处理REST API错误的正确姿势
- C语言之位运算
- C语言之预处理命令与用typedef命名已有类型
- spring-data-mongodb之MongoTemplate 删除操作
- 总结了一些指针易出错的常见问题(六)
- spring-data-mongodb之MongoTemplate 修改数据
- spring-data-mongodb之MongoTemplate 添加数据
- Cannot create a session after the response has been committed
- spring-data-mongodb之环境准备(1)
- java8 Lambda尝尝鲜
- spring-data-mongodb之批量更新操作
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- 【动手学深度学习笔记】之线性回归
- 【动手学深度学习笔记】之PyTorch实现softmax回归
- 三分钟解决Fashion-MNIST无法下载的问题
- 【动手学深度学习笔记】之实现softmax回归模型
- python实现简单爬虫功能
- Python 爬虫入门—— IP代理使用
- Python爬虫入门:爬取pixiv
- Linux PID 一网打尽
- 使用libimobiledevice&ifuse提取iOS沙盒文件
- 你不知道的LinkedList(二):LinkedList的增删操作真的会比ArrayList快吗
- jupyter notebook中的魔法命令%run和%timeit
- js 常用正则
- 非常实用的 Python 技巧
- JavaScript中arguments
- js通过class name获得元素