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 }
- 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 数组属性和方法
- 6.深入k8s:守护进程DaemonSet及源码分析
- 无所不能的Embedding 1 - Word2vec模型详解&代码实现
- 【JS】676- 1.1w字 | 初中级前端 JavaScript 自测清单 - 2
- matplotlib基础绘图命令之imshow
- 聊聊dubbo-go的broadcastCluster
- 爬取博客园文章
- 配置Python开发环境
- 部署Python应用
- 重写ThreadPoolTaskExecutor
- 聊聊dubbo-go的forkingCluster
- 创建多线程的4种方式
- 线程通讯wait¬ify
- 最新深度学习框架——OneFlow:新分布式训练(附源代码)
- 多线程相关概念
- MySQL安装教程