(大数)Computer Transformation hdu1041
Computer Transformation
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8688 Accepted Submission(s): 3282
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
用java,递推
递推:0->10 ;
1->01;
00->1010;
10->0110;
01->1001;
11->0101;
假设a[i]表示第i 步时候的00的个数,由上面的可以看到,00是由01 得到的,所以只要知道a[i-1]的01的个数就能够知道a[i]的00的个数了,那a[i-1]怎么求呢,同样看推导,01由1和00 得到,而第i步1的个数是2^(i-1),所以a[i]=2^(i-3)+a[i-2];(最后计算的是第i-2步情况)。
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
BigInteger a[]=new BigInteger[1001];
while(in.hasNextInt()) {
int n=in.nextInt();
a[1]=BigInteger.valueOf(0);
a[2]=BigInteger.valueOf(1);
a[3]=BigInteger.valueOf(1);
for(int i=4;i<=n;i++) {
a[i]=BigInteger.valueOf(0); //先进行初始化。
int m=i-3; //在大数的pow(m,n)中,n是int类型的,m是BigInteger类型的。
BigInteger q= new BigInteger("2");
a[i]=a[i].add(q.pow(m));
a[i]=a[i].add(a[i-2]);
}
System.out.println(a[n]);
}
}
}
(大数)Computer Transformation hdu1041的更多相关文章
- HDU 1041 Computer Transformation (简单大数)
Computer Transformation http://acm.hdu.edu.cn/showproblem.php?pid=1041 Problem Description A sequenc ...
- hdu_1041(Computer Transformation) 大数加法模板+找规律
Computer Transformation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/ ...
- Computer Transformation(简单数学题+大数)
H - Computer Transformation Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d &am ...
- Computer Transformation(规律,大数打表)
Computer Transformation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/ ...
- ACM学习历程—HDU1041 Computer Transformation(递推 && 大数)
Description A sequence consisting of one digit, the number 1 is initially written into a computer. A ...
- HDOJ-1041 Computer Transformation(找规律+大数运算)
http://acm.hdu.edu.cn/showproblem.php?pid=1041 有一个初始只有一个1的串 每次都按①0 -> 10;②1 -> 01;这两条规则进行替换 形如 ...
- HDU 1041 Computer Transformation(找规律加大数乘)
主要还是找规律,然后大数相乘 #include<stdio.h> #include<string.h> #include<math.h> #include<t ...
- Computer Transformation(hdoj 1041)
Problem Description A sequence consisting of one digit, the number 1 is initially written into a com ...
- HDU 1041 Computer Transformation 数学DP题解
本题假设编程是使用DP思想直接打表就能够了. 假设是找规律就须要数学思维了. 规律就是看这些连续的0是从哪里来的. 我找到的规律是:1经过两次裂变之后就会产生一个00: 00经过两次裂变之后也会产生新 ...
随机推荐
- Python_装饰器_29
# 装饰器形成的过程 : 最简单的装饰器 有返回值的 有一个参数 万能参数 # 装饰器的作用 # 原则 :开放封闭原则 # 语法糖 :@ # 装饰器的固定模式 import time # print( ...
- db2安装
官网下载: DB2 11.1 data server trial for Linux® on AMD64 and Intel® EM64T systems (x64)v11.1_linuxx64_se ...
- <构建之法>13——17章的读后感
第13章:软件测试 问题:对于这么多种的测试方法,怎么才能最有效的选取? 第14章:质量保证 问题:很多工程师都把大多数时间花在软件质量上.一成不变是无法创新的.如何在保证质量的情况下,又得到创新呢? ...
- JavaScript 作用域链与闭包
作用域链 在某个作用域访问某个变量或者函数时,会首先在自己的局部环境作用域中搜寻变量或者函数,如果本地局部环境作用域中有该变量或者函数,则就直接使用找到的这个变量值或者函数:如果本地局部环境作用域中没 ...
- js排序方法
function swap(ary, x, y) { if (x === y) return let temp = ary[x] ary[x] = ary[y] ary[y] = temp } //生 ...
- Win10 1803 Spring Creators update Consumer edition的版本记录
安装时可选择的版本列表 安装完之后的版本: 3. 时间线更新 4. Focus assistant
- bat脚本的写法
当你每次都要输入相同的命令时,可以把这么多命令存为一个批处理,从此以后,只要运行这个批处理,就相当于打了几行.几十行命令.下面以Nginx服务的停止脚本为例写一个bat批处理文件: 1.新建nginx ...
- super 使用以及原理
用super也很久了,但是一直没有关注过他的原理.最近开始越来越多关注python更底层的实现和奇技淫巧.看到该方法越发使用得多所以也研究了一波 平时单继承可能是我们遇到最多的情况.无非就是类似情况. ...
- 最实用的深度学习教程 Practical Deep Learning For Coders (Kaggle 冠军 Jeremy Howard 亲授)
Jeremy Howard 在业界可谓大名鼎鼎.他是大数据竞赛平台 Kaggle 的前主席和首席科学家.他本人还是 Kaggle 的冠军选手.他是美国奇点大学(Singularity Universi ...
- Python连接字符串用join还是+
我们先来看一下用join和+连接字符串的例子 str1 = " ".join(["hello", "world"]) str2 = &quo ...