Computer Transformation

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6946    Accepted Submission(s): 2515

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
题解:f(n)=2*f(n-2)+f(n-1)由于每个n-2的00生成两个01,在n的地方就会生成两个00;n-1的00在n生成一个00;由此可以找出规律;
代码:
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
#define mem(x,y) memset(x,y,sizeof(x))
typedef long long LL;
const int MAXN=;
char dp[MAXN][MAXN];
char c[MAXN];
int x[MAXN],y[MAXN],z[MAXN];
void bigsum(char *a,char *b){
int len1,len2;
mem(x,);mem(y,);mem(z,);
len1=strlen(a);len2=strlen(b);
int len=max(len1,len2);
for(int i=len1-,j=;i>=;i--,j++)x[j]=a[i]-'';
for(int i=len2-,j=;i>=;i--,j++)y[j]=b[i]-'';
for(int i=;i<len;i++){
z[i]=x[i]+y[i]+z[i];
z[i+]+=z[i]/;
z[i]%=;
if(z[len])len++;
}
for(int i=len-,j=;i>=;i--,j++)c[j]=z[i]+'';
c[len]='\0';
}
int main(){
int n;
dp[][]='';dp[][]='\0';
dp[][]='';dp[][]='\0';
for(int i=;i<=;i++){
bigsum(dp[i-],dp[i-]);
bigsum(c,dp[i-]);
memcpy(dp[i],c,sizeof(c));
}
while(~scanf("%d",&n)){
printf("%s\n",dp[n]);
}
return ;
}
 

Computer Transformation(规律,大数打表)的更多相关文章

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

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

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

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

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

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

  4. (大数)Computer Transformation hdu1041

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

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

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

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

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

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

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

  8. UVA - 1647 Computer Transformation(计算机变换)(找规律)

    题意:初始串为一个1,每一步会将每个0改成10,每个1改成01,因此1会依次变成01,1001,01101001,……输入n(n<=1000),统计n步之后得到的串中,"00" ...

  9. hdu 5351 规律+大数

    题目大意:定义了一种fib字符串,问第n个fib串的前m个字母前后相等串的最大长度,大约就是这样的 其实主要读完题意的时候并没有思路,但是列几个fib字符串就会发现,除了fib1以外,所有串的前面都是 ...

随机推荐

  1. png的格式及像素存储分析

    从图片的数据块存储方式来看png分两种 1.索引色模式存储.png8的索引色透明就采取该种方式.该种方式是将颜色存在png的可选模块调色板中,调色板的色彩存储格式为RGB(各1byte).而图片的数据 ...

  2. VS2010/MFC:模态对话框及其弹出过程

    模态对话框及其弹出过程 加法计算器对话框程序大家照着做一遍后,相信对基于对话框的程序有些了解了,有个好的开始对于以后的学习大有裨益.趁热打铁,这一节讲讲什么是模态对话框和非模态对话框,以及模态对话框怎 ...

  3. 首页 导航栏隐藏 下一级页面显示,pop回来遇到的问题

    - (void)viewWillAppear:(BOOL)animated {    [super viewWillAppear:animated];    [self.navigationContr ...

  4. nyoj-709-异形卵(水题)

    异 形 卵 时间限制:1000 ms  |  内存限制:65535 KB 难度: 描写叙述 我们探索宇宙,是想了解浩瀚星空的奥妙.但我们却非常少意识到宇宙深处藏匿的危急,它们无时无刻不紧盯着我们的地球 ...

  5. PHP程序猿必须学习的第二课——站点安全问题预防

    作为PHP程序猿.第一课我们学习了基本的语法.那么在熟悉基本的语法之后我们应该学些什么呢?我觉得是安全问题.安全问题基于一个站点宛如基石,一着不慎,意味着灾难性的事故. 这里主要就提三点最简单,也是最 ...

  6. 【翻译】【中英对照】【企业库6】动手实验 Hands-On Lab 日志应用程序块索引页

    Logging Application Block Hands-On Lab for Enterprise Library 企业库的日志应用程序块动手实验 This walkthrough shoul ...

  7. aliyun硬盘挂载

    实在难以忍受公司服务器的网络问题,停用了半年的aliyun服务器今天终于决定启用了. 购买的时候是40G的硬盘空间,首先查了一硬盘情况结果发现有一个分区居然没有挂载.  第一步是创建一个分区 输入命令 ...

  8. JavaScript中的事件处理程序

    JavaScript和HTML之间的交互是通过事件实现的.事件,就是文档或者浏览器窗口中发生的一些特定的交互瞬间.可以使用事件处理程序来预订事件,以便在事件发生的时候执行响应的代码.这种观察者模式的模 ...

  9. UIScreen的 bound、frame、scale属性

    CGRect bound = [[UIScreen mainScreen] bounds];  // 返回的是带有状态栏的Rect   CGRect frame = [[UIScreen mainSc ...

  10. strcpy_s

    char src[5]="abcd"; char *des=new char[str.length(src)+1];   // length()不计\0 strcpy_s(des, ...