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
step 1:01
step 2:1001
step 3:0110 1001
step 4:1001 0110 0110 1001
step 5:0110 1001 1001 0110 1001 0110 0110 1001
 /*找规律,0 1 1 3 5 11 21 43 85,找出递推关系f(n)=2*f(n-2)+f(n-1),*/
#include<stdio.h>
int a[][]={{},{},{},{}};
int b[]={};
int calc()/*由于n可以取到1000,2^1000超出long long,必须要用数组按位存储,所以考大数*/
{
int i=;
for(i=;i<;i++)
{
int c,j;
for(c=,j=;j<;j++)/*利用b数组存储2*f(n-2)*/
{
b[j]=b[j]*+c;/*c为余数*/
c=b[j]/;
b[j]=b[j]%;
}
for(c=,j=;j<;j++)/* 2*f(n-2)+f(n-1) */
{
a[i][j]=b[j]+a[i-][j]+c;
c=a[i][j]/;
a[i][j]=a[i][j]%;
}
}
}
int main()
{
int n,i,k=;
calc();
while(~scanf("%d",&n))
{
if(n==)
printf("");
else
{
k=;
for(i=;i>=;i--)
{
if(a[n][i]||k)
{
printf("%d",a[n][i]);
k=;
}
}
}
printf("\n");
}
}

Computer Transformation(hdoj 1041)的更多相关文章

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

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

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

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

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

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

  4. (大数)Computer Transformation hdu1041

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

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

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

  6. HDU 1041 Computer Transformation

    这道题目的意思是:一开始有一个数字 1 ,在接下来的时间中,计算机会按照如下规则进行扩展:                0 –> 1 0                1 –> 0 1 ...

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

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

  8. HDU 1041 Computer Transformation 数学DP题解

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

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

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

随机推荐

  1. php 去掉 头尾 空格 2种方法

    看似很简单的问题,其实还是有点坑的,首先这里 空格转义,不是字符串,直接用trim()是去不掉. 1,用preg_replace替换 $test = " dfadad 论责民与三英的关系77 ...

  2. 论JS的重要性

    最近有学习了JavaScript,学习的过程中发现js对于前端工程师来说可以是最终要的一部分. 个人认为js就是一门语言,如果把前端比作一个人的身体,那么html就是一个人的结构,css就是这个人长的 ...

  3. keil C51 指针总结

    变量就是一种在程序执行过程中其值能不断变化的量.要在程序中使用变量必须先用标识符作为变量名,并指出所用的数据类型和存储模式,这样编译系统才能为变量分配相应的存储空间.定义一个变量的格式如下: [存储种 ...

  4. spring springMVC mybatis 集成

    最近闲来无事,整理了一下spring springMVC mybatis 集成,关于这个话题在园子里已经有很多人写过了,我主要是想提供一个完整的demo,涵盖crud,事物控制等. 整个demo分三个 ...

  5. WebSocket C# Demo

    WebSocket 规范 WebSocket 协议本质上是一个基于 TCP 的协议.为了建立一个 WebSocket 连接,客户端浏览器首先要向服务器发起一个 HTTP 请求,这个请求和通常的 HTT ...

  6. jquery判断元素是否隐藏的多种方法

    第一种:使用CSS属性 复制代码 代码如下: var display =$('#id').css('display'); if(display == 'none'){    alert("被 ...

  7. VS2010常用的调试方法

    1.一直以来都没用过command window, F5以后可以这样用,直接对一个函数,或者变量做模块测试 以下还有一些常用的技巧: 1 悬停鼠标查看表达式值 调试是很有挑战性的.比如在函数内逐步运行 ...

  8. 【LeetCode练习题】Combination Sum

    Combination Sum Given a set of candidate numbers (C) and a target number (T), find all unique combin ...

  9. Capture the Flag(模拟)

    Capture the Flag Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge In computer se ...

  10. 购买DigtalOcean VPS 以及 连接Linux

    1.DigtalOcean简介 digitalocean是一家成立于2012年的总部设置在纽约的云主机商家,眼下在荷兰的阿姆斯特丹(AMS1.AMS2).美国的纽约(NYC1.NYC2)和旧金山(SF ...