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步情况)。

  1. import java.math.BigDecimal;
  2. import java.math.BigInteger;
  3. import java.util.Scanner;
  4. public class Main {
  5. public static void main(String[] args) {
  6. Scanner in = new Scanner(System.in);
  7. BigInteger a[]=new BigInteger[1001];
  8. while(in.hasNextInt()) {
  9. int n=in.nextInt();
  10. a[1]=BigInteger.valueOf(0);
  11. a[2]=BigInteger.valueOf(1);
  12. a[3]=BigInteger.valueOf(1);
  13. for(int i=4;i<=n;i++) {
  14. a[i]=BigInteger.valueOf(0); //先进行初始化。
  15. int m=i-3; //在大数的pow(m,n)中,n是int类型的,m是BigInteger类型的。
  16. BigInteger q= new BigInteger("2");
  17. a[i]=a[i].add(q.pow(m));
  18. a[i]=a[i].add(a[i-2]);
  19. }
  20. System.out.println(a[n]);
  21. }
  22. }
  23. }

(大数)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. linux-IO重定向-文本流重定向

    输出重定向的追加和覆盖 标准输出就这两种: 覆盖和追加 >> 是重定向操作符 1 是 命令的文件描述符 重定向操作符合文件描述符之间不能存在空白符 否则1会被当做是文件被读取 将正确和错误 ...

  2. B. Divisor Subtraction

    链接 [http://codeforces.com/contest/1076/problem/B] 题意 给你一个小于1e10的n,进行下面的运算,n==0 结束,否则n-最小质因子,问你进行多少步 ...

  3. Proxy 示例

    package cn.proxy03; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; imp ...

  4. 第三个Sprint冲刺第九天(燃尽图)

  5. C++中struct 和 class的区别

    首先,C++中类的定义,从狭义上理解,就是我们使用的class类型.从广义上,类就是定义了一个新的类型和新的作用域,它具有成员函数和成员数据. 而对广义类定义的实现分为两种,一种是使用struct实现 ...

  6. CentOS 7 Install Adobe Flash Player

    From Officail Adobe Flash Site don't down (YUM )adobe-release-x86_64-1.0-1.noarch.rpm,but to downloa ...

  7. Macbook系统环境安装wget的2个方法 - 传统包及Homebrew安装

    文章目录 这里有2个方法可以安装wget命令工具: 考虑到自身项目的拓展需要,朋友建议学习Python爬虫这样对于做大数据采集有较大的帮助,老蒋虽然每天也都接触一些脚本和程序的修改,但是并没有专业和系 ...

  8. zabbix2.2 - FromDual.MySQL.check" became not supported

    升级zabbix后发现zabbix server日志中多个实例报错如下: 27974:20171227:113001.724 item "实例name:FromDual.MySQL.chec ...

  9. Lodop窗口的按钮、权限,隐藏或设置功能不可用

    Lodop隐藏某个按钮或部分,具体参考Lodop技术手册 SET_SHOW_MODE篇.以下是几个例子,(对应下图图片): 第一种:LODOP.SET_SHOW_MODE ("HIDE_PB ...

  10. anaconda2安装cv2

    http://m.blog.csdn.net/u010167269/article/details/62447648 下载离线安装包:https://anaconda.org/menpo/opencv ...