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. RHEL 7.2 源码安装Python 3.6.2报错

    报错代码:zipimport.ZipImportError: can't decompress data; zlib not available 一条命令解决:yum install zlib-dev ...

  2. UVALive - 6428(扩展欧几里德)

    http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=48388 前段时间偶然碰到的一道题,今天突然想到没把它记录下来. 比较不错的扩 ...

  3. qconshanghai2017

    https://2017.qconshanghai.com/schedule 第一天 (2017/10/17 星期二) 时间 日程 07:45-09:00 签到 上午 主题演讲 软件质量优化与平台创新 ...

  4. AJPFX总结方法的特点

    它可以实现独立的功能; 必须定义在类里面; 它只有被调用才会执行; 它可以被重复使用; 方法结束后方法里的对象失去引用;   如何定义一个功能,并通过方法体现出来: ① 明确该功能运算后的结果.明确返 ...

  5. Delphi定时器控件TTimer“一睡不醒”问题研究

    1,试验1—基础代码 1.1页面控件与代码 定时器 Timer1 Timer_work Interval 1000 1500 Enabled True True Ontimer事件 then exit ...

  6. react基础语法(四) state学习

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  7. 在DLL中创建窗口时一个值得注意的地方 — UnregisterClass

    背景描述: 今天要测试一份注入代码,拿以前写的创建窗口的DLL来做测试. 第一次注入时一切正常,窗口被成功创建并显示,但在第二次加载时窗口没有显示出来. 经过研究发现在第二次加载DLL时Registe ...

  8. Tomcat和搜索引擎网络爬虫的攻防

    不知道广大程序员朋友们注意到一个现象么?使用百度是无法搜索到淘宝网的网页.为什么会造成这种现象?这就要从网络爬虫说起了. 咱们程序员假如自己搭设个人网站,在上面分享少量自己的技术文章,面临的一个重要问 ...

  9. dzzoffice网盘应用有着最强大的团队、企业私有网盘功能,并且全开源无功能限制。

    企业,团队多人使用dzzoffice的网盘应用,灵活并且功能强大. 支持个人网盘,机构部门,群组,并可根据使用情况开启关闭.例如可只开启群组功能.   可通过后缀,标签自定义类型进行快捷筛选   全面 ...

  10. Unity查找物体的四大主流方法及区别

    GameObject.Find()优点: 使用简单方便不会因为重名而报错,同时查找的是自上而下的第一个物体缺点 不能查找被隐藏的物体,否则出现“空引用异常”,这是很多新人在查找出现空引用bug的原因. ...