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

题目大意就是有0-> 10, 1->01这两种变换,起始状态是1,让求某次变换后连续两个0的个数,此处有且仅两个0连续。

首先枚举前几项的话

0:1

1:01

2:1001

3:01101001

4:1001011001101001

5:01101001100101101001011001101001

……

发现两个个规律,

1:

所有项前一半和后一半互反,此外,偶数项对称。

想来也是,只要满足某个前一项前一半和后一半互反,0->10,1->01后,自然造成后一项同样互反的形式。

同样的前一个偶数项的对称会导致后面奇数项的前一半和后一半都对称,自然导致后一个偶数项对称。

此处严谨证明应由数学归纳法。

2:

后一项等于前一项取反拼上前一项。

发现奇数项由于前后互反,在交接处会形成01,那么下一项在对称情况下,交界处必形成1001。所以偶数项的0对会多生成一个。

有了这些就知道了两项间的关系。

于是由2得:

zero[i] = zero[i-1]+one[i-1]+(i-1)%2;

one[i] = zero[i-1]+one[i-1];

由于递推式看起来增长速度就和费波拉契有的一比,估计需要大数。实测确实需要。

代码:

import java.math.BigInteger;
import java.util.Scanner; public class Main
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
BigInteger one[] = new BigInteger[];
BigInteger zero[] = new BigInteger[];
one[] = new BigInteger("");
one[] = new BigInteger("");
zero[] = new BigInteger("");
zero[] = new BigInteger("");
for (int i = ; i <= ; ++i)
{
zero[i] = zero[i-].add(one[i-]).add(new BigInteger(Integer.toString((i-)%)));
one[i] = zero[i-].add(one[i-]);
}
int n;
while (input.hasNext())
{
n = input.nextInt();
System.out.println(zero[n]);
}
}
}

ACM学习历程—HDU1041 Computer Transformation(递推 && 大数)的更多相关文章

  1. ACM学习历程—HDU5396 Expression(递推 && 计数)

    Problem Description Teacher Mai has n numbers a1,a2,⋯,an and n−1 operators("+", "-&qu ...

  2. ACM学习历程—UESTC 1217 The Battle of Chibi(递推 && 树状数组)(2015CCPC C)

    题目链接:http://acm.uestc.edu.cn/#/problem/show/1217 题目大意就是求一个序列里面长度为m的递增子序列的个数. 首先可以列出一个递推式p(len, i) =  ...

  3. ACM学习历程——ZOJ 3822 Domination (2014牡丹江区域赛 D题)(概率,数学递推)

    Description Edward is the headmaster of Marjar University. He is enthusiastic about chess and often ...

  4. ACM学习历程—HDU1028 Ignatius and the Princess III(递推 || 母函数)

    Description "Well, it seems the first problem is too easy. I will let you know how foolish you ...

  5. ACM学习历程—HDU 5326 Work(树形递推)

    Problem Description It’s an interesting experience to move from ICPC to work, end my college life an ...

  6. ACM学习历程—SNNUOJ 1116 A Simple Problem(递推 && 逆元 && 组合数学 && 快速幂)(2015陕西省大学生程序设计竞赛K题)

    Description Assuming a finite – radius “ball” which is on an N dimension is cut with a “knife” of N- ...

  7. ACM学习历程—NPU 2015年陕西省程序设计竞赛网络预赛(正式赛)F题 和谐的比赛(递推)

    Description 今天西工大举办了一场比赛总共有m+n人,但是有m人比较懒没带电脑,另外的n个人带了电脑.不幸的是,今天机房的电脑全坏了只能用带的电脑,一台电脑最多两人公用,确保n>=m. ...

  8. 完成了C++作业,本博客现在开始全面记录acm学习历程,真正的acm之路,现在开始

    以下以目前遇到题目开始记录,按发布时间排序 ACM之递推递归 ACM之数学题 拓扑排序 ACM之最短路径做题笔记与记录 STL学习笔记不(定期更新) 八皇后问题解题报告

  9. ACM学习历程—HDU5667 Sequence(数论 && 矩阵乘法 && 快速幂)

    http://acm.hdu.edu.cn/showproblem.php?pid=5667 这题的关键是处理指数,因为最后结果是a^t这种的,主要是如何计算t. 发现t是一个递推式,t(n) = c ...

随机推荐

  1. GET,POST

    HTTPHTTP(即超文本传输协议)是现代网络中最常见和常用的协议之一,设计它的目的是保证客户机和服务器之间的通信.HTTP 的工作方式是客户端与服务器之间的 “请求-响应” 协议.客户端可以是 We ...

  2. 【问题解决】Tomcat 启动时闪退或提示“Neither the JAVA_HOME or the JRE_HOME environmental variable is defined.”

    问题解决思路: 1.分析startup.bat启动脚本:发现其调用了catalina.bat,而catalina.bat调用了setclasspath.bat 2.在setclasspath.bat的 ...

  3. 【BZOJ3510】首都 LCT维护子树信息+启发式合并

    [BZOJ3510]首都 Description 在X星球上有N个国家,每个国家占据着X星球的一座城市.由于国家之间是敌对关系,所以不同国家的两个城市是不会有公路相连的. X星球上战乱频发,如果A国打 ...

  4. 记录-阿里云Oss文件上传

    public class OssUtil { /** * 上传图片 * @param file * @param request * @return */ public static Map<S ...

  5. Android系统移植与调试之------->MTK 标准编译命令

    命令格式:./maketek [option] [project] [action] [modules]Option:   -t ,-tee :输出log信息到当前终端   -o , -opt=-- ...

  6. eclipse js调试

    问题: js经常会被浏览器给cache,不管怎么刷都是原来的. 解决: 暂时有一个方法,一刷新就好,下面的截图: 1)先打开 <开发者工具> 2)找到Sources 3)Page中找到你的 ...

  7. Java中的String,StringBuilder,StringBuffer三者的区别(转发:https://www.cnblogs.com/su-feng/p/6659064.html)

    最近在学习Java的时候,遇到了这样一个问题,就是String,StringBuilder以及StringBuffer这三个类之间有什么区别呢,自己从网上搜索了一些资料,有所了解了之后在这里整理一下, ...

  8. python基础22------python基础之基于tcp和udp的套接字

    一.TCP套接字 1.low版tcp套接字 服务器端 客户端 2.改进版tcp套接字 服务端 客户端 二.UDP的套接字 服务器 客户端 注:udp的套接字可以支持多个客户端同时访问,但tcp套接字就 ...

  9. 图片的等比缩放和Logo水印

    /** * 等比缩放函数(以保存的方式实现) * @param string $picname 被缩放的处理图片源 * @param int $maxx 缩放后图片的最大宽度 * @param int ...

  10. Elasticsearch for python API模块化封装

    Elasticsearch for python API模块化封装 模块的具体功能 检测Elasticsearch节点是否畅通 查询Elasticsearch节点健康状态 查询包含的关键字的日志(展示 ...