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的更多相关文章

  1. HDU 1041 Computer Transformation (简单大数)

    Computer Transformation http://acm.hdu.edu.cn/showproblem.php?pid=1041 Problem Description A sequenc ...

  2. hdu_1041(Computer Transformation) 大数加法模板+找规律

    Computer Transformation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/ ...

  3. Computer Transformation(简单数学题+大数)

    H - Computer Transformation Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d &am ...

  4. Computer Transformation(规律,大数打表)

    Computer Transformation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/ ...

  5. ACM学习历程—HDU1041 Computer Transformation(递推 && 大数)

    Description A sequence consisting of one digit, the number 1 is initially written into a computer. A ...

  6. HDOJ-1041 Computer Transformation(找规律+大数运算)

    http://acm.hdu.edu.cn/showproblem.php?pid=1041 有一个初始只有一个1的串 每次都按①0 -> 10;②1 -> 01;这两条规则进行替换 形如 ...

  7. HDU 1041 Computer Transformation(找规律加大数乘)

    主要还是找规律,然后大数相乘 #include<stdio.h> #include<string.h> #include<math.h> #include<t ...

  8. Computer Transformation(hdoj 1041)

    Problem Description A sequence consisting of one digit, the number 1 is initially written into a com ...

  9. HDU 1041 Computer Transformation 数学DP题解

    本题假设编程是使用DP思想直接打表就能够了. 假设是找规律就须要数学思维了. 规律就是看这些连续的0是从哪里来的. 我找到的规律是:1经过两次裂变之后就会产生一个00: 00经过两次裂变之后也会产生新 ...

随机推荐

  1. 求去掉一条边使最小割变小 HAOI2017 新型城市化

    先求最小割,然后对残量网络跑Tarjan.对于所有满流的边,若其两端点不在同一个SCC中,则这条边是满足条件的. 证明见 来源:HAOI2017 新型城市化

  2. cf946d 怎样逃最多的课dp

    来源:codeforces                                              D. Timetable Ivan is a student at Berland ...

  3. pl/sql破解方法

    转载源:http://blog.csdn.net/oscar999/article/details/2123803 打开注册表在run下输入regedit删除1.HKEY_CURRENT_USER/S ...

  4. ES6.0简单了解

    Case 1:let.const var的缺陷 1.可以重复声明变量 2.无法限制修改(没有常量) 3.没有块级作用域 let和const可以弥补var的缺陷 let: 不能重复声明,用来声明变量,声 ...

  5. Vue.directive注册指令

    指令定义函数提供了几个钩子函数(可选): vue指令的生命周期 bind: 只调用一次,指令第一次绑定到元素时调用,用这个钩子函数可以定义一个在绑定时执行一次的初始化动作. inserted: 被绑定 ...

  6. php的四种基本算法

    /* 冒泡算法:结果从小到大,规则类似波浪推动的沙滩,先初始阈值为 0,初始第一次波浪之后,如果发现有左值比右边的大,就改变阈值并且完成波浪推动,重新初始化阈值为0,如此往复,直到没有阈值改变的情况出 ...

  7. PP模块的主要功能及标准业务流程

    主要功能:1.SOP (Sales and operations Planning).2.资源分配计划划 (Distribution Resource Planning)3.生产计划编制 (Produ ...

  8. 软件工程_10th weeks

    不管是什么原因,都没有在周三24:00前发布博客,赶紧用行动补上~ psp DATE START_TIME END_TIME EVENT TYPE     DELTA 5.8 9:00 12:00 论 ...

  9. 选择 Delphi 2007 ( CodeGear Delphi 2007 for Win32 Version 11.0.2837.9583 ) 的理由

    选择 Delphi 2007 ( CodeGear Delphi 2007 for Win32 Version 11.0.2837.9583 ) 的理由 我不喜欢用InstallRite的全自动安装包 ...

  10. codeforces620A

    Professor GukiZ's Robot CodeForces - 620A 机器人很好玩 一开始在(x1,y1) 最后在(x2,y2) 每秒钟内横坐标最多变化1(也可以不变化)纵坐标也是 问最 ...