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. MySQL5.5升级到5.6

    5.6的新的特性 .支持GTIDs,Failover.多线程复制. 新增binlog_row_image只记录row格式下所用字段的修改(而不是像以前一样记录全部列),节省空间等资源: master. ...

  2. window服务 调试步骤

    方法一: 1.编译windows服务项目工程 2.把服务注册到系统服务上 3.在visual studio 编辑器中,打断点,用 Debug  进程调试 方法二: 在Onstart 方法中,加上 De ...

  3. 转 Java 208道面试题及部分答案 补充部分答案

    转自https://www.cnblogs.com/chen1005/p/10481102.html   ---恢复内容开始--- 一.Java 基础 1.JDK 和 JRE 有什么区别? 答:JRE ...

  4. 【转】码云source tree 提交超过100m 为什么大文件推不上去

    码云source tree 提交超过100m 为什么大文件推不上去 2017年01月12日 16:50:51 阅读数:7634 git -c diff.mnemonicprefix=false -c ...

  5. mysql多表查询20题

    +-------------------+| Tables_in_dapeng3 |+-------------------+| class || course || s1 || score || s ...

  6. iOS html格式解析

    使用TFHpple解析html https://github.com/topfunky/hpple 前期准备工作 引入静态库文件 添加库文件的 header search paths(注意,必须选中 ...

  7. HDU 5778 abs (暴力枚举)

    abs Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Problem De ...

  8. ElasticSearch使用spring-data-elasticSearch的用法

    spring-data-Elasticsearch 使用之前,必须先确定版本,elasticsearch 对版本的要求比较高. spring和elasticsearch有两种链接方式,一种是用TCP协 ...

  9. uva1613 K-Graph Oddity

    题目要求k>=最大度数:观察,颜色数量和度数的关系,得颜色数=最大度数+1(偶数)//最大度数(奇数) 可以满足染色关系一个点和周围的点的颜色数加起来最大为它的度数+1: k=所有点中最大的度. ...

  10. C++:new的使用

    这里先开个头,以后做详细补充个: new 分配内存失败后会返回空指针: