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

http://acm.hdu.edu.cn/showproblem.php?pid=1041

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
 
Source

似曾相识的一题,连递推数列都是一模一样的,好醉。。

其实举几组样例多举几组就可以发现规律了,每次出现1001这种时都是上一个序列中有01这种子串,所以看上一串有多少个01字串就知道下一个有多少个1001,所以不难发现递推公式a[i]=a[i-1]+2*a[i-2](i>=3);这个和那个填骨牌的题一模一样,但注意数据范围,就算2的1000次方也是很大的,所以用二维数组存储大数,开到400就够了;

#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
//const int INF=0x3f3f3f3f;
const int N=1000+10;
int a[N][400];
int main()
{
memset(a,0,sizeof(a));
int n,i,j;
a[1][0]=0,a[2][0]=1;
int c=0;
for(i=3;i<=1000;i++)
{
c=0;
for(j=0;j<=400;j++)//核心--大数;
{
a[i][j]=a[i-1][j]+2*a[i-2][j]+c;
c=a[i][j]/10;
a[i][j]%=10;
}
}
while(~scanf("%d",&n))
{
if(n==1)
printf("0\n");
else
{
for(j=399;j>=0;j--)
if(a[n][j])
break;
for(i=j;i>=0;i--)
printf("%d",a[n][i]);
printf("\n");
}
}
return 0;
}

其实静下心来想想思路到A出这道题不过10多分钟,这如果在比赛中就会有绝对的优势。

HDU-1041-Computer Transformation,大数递推,水过~~的更多相关文章

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

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

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

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

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

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

  4. HDU 1041 Computer Transformation 数学DP题解

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

  5. HDU 1041 Computer Transformation

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

  6. HDU 5950 Recursive sequence 【递推+矩阵快速幂】 (2016ACM/ICPC亚洲区沈阳站)

    Recursive sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

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

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

  8. 题解报告:hdu 2084 数塔(递推dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2084 Problem Description 在讲述DP算法的时候,一个经典的例子就是数塔问题,它是这 ...

  9. POJ 1737 Connected Graph (大数+递推)

    题目链接: http://poj.org/problem?id=1737 题意: 求 \(n\) 个点的无向简单(无重边无自环)连通图的个数.\((n<=50)\) 题解: 这题你甚至能OEIS ...

随机推荐

  1. PoolManager插件(转载)

    http://www.xuanyusong.com/archives/2974 前几天我在博客里面分享了为什么Unity实例化很慢的原因,并且也分享了一个缓存池的工具.有朋友给我留言说PoolMana ...

  2. zoj3768Continuous Login

    链接 这题通过暴力可以看出最多不超过3 具体为什么..等着看大牛的题解. 可以预处理出来两个数之和 用bool存下 然后枚举一个数 二分剩余数的位置就可以了 勉强可过 #include <ios ...

  3. Windows API函数大全二

    4. API之打印函数 AbortDoc 取消一份文档的打印 AbortPrinter 删除与一台打印机关联在一起的缓冲文件 AddForm 为打印机的表单列表添加一个新表单 AddJob 用于获取一 ...

  4. 如何从GAC中拷贝文件出来 C:\Windows\assembly

    方法一:命令行拷贝. 开始--运行--cmd--"cd C:\WINDOWS\assembly".一般自己开发的dll都在GAC_MSIL这个文件夹下面,按照我如下的截图就可以拷贝 ...

  5. 【学习笔记】深入理解js原型和闭包(15)——闭包

    前面提到的上下文环境和作用域的知识,除了了解这些知识之外,还是理解闭包的基础. 至于“闭包”这个词的概念的文字描述,确实不好解释,我看过很多遍,但是现在还是记不住. 但是你只需要知道应用的两种情况即可 ...

  6. 【Win32汇编】编译环境配置

    开始学习[Win32汇编],编译过程较为繁琐,做个记录. 使用 MASM32 提供的 ml.exe 和 link.exe,以及 VS2013 中的 nmake.exe 和资源编辑器. ml.exe: ...

  7. [Github筆記] 清除所有 Commit 紀錄

    # 把原來的 git 移除掉 sudo rm .git -r # 初始化 git init git remote add origin https://github.com/username/repo ...

  8. 15分钟学会使用Git

    http://blog.csdn.net/u013510614/article/details/50588446 主体思想 Git作为一个复杂的版本控制系统,命令之多,相信很多小白已经望而却步,有的尝 ...

  9. example - 在这里插入一句话的简介

    总览 (SYNOPSIS) example [options] arguments 描述 (DESCRIPTION) 在这里插入描述 man9 应当是 “内核文档” 但是由于内核文档一般不以 man ...

  10. promise 里面的 console.info 打印信息 并不准确,后期有修改对象数据,会覆盖,影响之前的显示

    promise 里面的 console.info 打印信息 并不准确,后期有修改对象数据,会覆盖,影响之前的显示