Computer Transformation(规律,大数打表)

时间:2021-12-17 00:49:49

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 &lpar;简单大数&rpar;

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

  2. hdu&lowbar;1041&lpar;Computer Transformation&rpar; 大数加法模板&plus;找规律

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

  3. Computer Transformation&lpar;简单数学题&plus;大数&rpar;

    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&Tab; Computer Transformation(找规律加大数乘)

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

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

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

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

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

  8. UVA - 1647 Computer Transformation&lpar;计算机变换&rpar;&lpar;找规律&rpar;

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

  9. hdu 5351 规律&plus;大数

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

随机推荐

  1. java高新技术-类加载器

    1.类加载器及委托机制的深入分析 > 类加载器的作用:一个java文件中的出现的类,首先要把这个类的字节码加载到内存中,这个类的信息放在硬盘的classPath下的class文件中,  把cla ...

  2. &period;NET&colon; C&num;&colon; StopWatch

    StopWatch class is used for calculate the timespan for that procedure. In Debug Mode it will be very ...

  3. VS2012简单的使用感受&plus;插件推荐

    VS2012简单的使用感受+插件推荐http://www.cnblogs.com/tangge/archive/2013/03/12/2955367.html

  4. Spring depends-on介绍

    <!-- redis配置 --> <bean id="jedisPoolConfig" class="redis.clients.jedis.Jedis ...

  5. Delphi的RTTI还分为对类和对象的判断,以及对普通属性的判断——相比之下,C&plus;&plus;的RTTI实在太弱!

    堂堂C++沦落到这个地步,也实在是够可怜的.

  6. Java IO(一):IO和File

    一.IO 大多数的应用程序都要与外部设备进行数据交换,最常见的外部设备包含磁盘和网络.IO就是指应用程序对这些设备的数据输入与输出,Java语言定义了许多类专门负责各种方式的输入.输出,这些类都被放在 ...

  7. php之array&lowbar;column 的使用

    听说只有大牛级的高工才知道的函数array_column () 讲真,我才知道. (PHP 5 >= 5.5.0, PHP 7) array_column - 返回数组中指定的一列 说明 arr ...

  8. &lbrack;Swift&rsqb;LeetCode468&period; 验证IP地址 &vert; Validate IP Address

    Write a function to check whether an input string is a valid IPv4 address or IPv6 address or neither ...

  9. Fedora 19安装mysql

    安装数据库模块 Mysql和Mysql-server#yum install mysql mysql-server 开启mysql服务#systemctl start mysqld.service同样 ...

  10. javascript篇-typeof&comma;instanceof&comma;constructor&comma;toString判断数据类型的用法和区别

    javascript基本数据类型有:string,number,Boolean,undefined,null 引用类型(复杂类型):object, ES6中新增了一种数据类型:Symbol 以上数据类 ...