Computer Transformation

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

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
 

规律:数串的右边一般是上一个数串,数串的左半边是上两个数串+上一个数串的左半区

 #include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<iostream>
using namespace std;
#define ll long long
const int N = ;
struct Node{
string sum;
string leftsum;
int left,right;//zuo ban qu
}node[N]; string add(string s1,string s2){ //大数 s1 + s2
if(s1.length()<s2.length()){
string temp=s1;
s1=s2;
s2=temp;
}
for(int i=s1.length()-,j=s2.length ()-;i>=;i--,j--){
s1[i]=char(s1[i]+( j>= ? s2[j]-'' : ));
if(s1[i]-''>=) {
s1[i]=char( (s1[i]-'')%+'' );
if(i) s1[i-]++;
else s1=""+s1;
}
}
return s1;
} void init()
{
/* for(int i = 0; i < N; i++){
node[i].sum ="0";
node[i].leftsum = "0";
}*/
node[].sum = "", node[].left = , node[].right = , node[].leftsum = "";
node[].sum = "", node[].left = , node[].right = , node[].leftsum = "";
for(int i = ; i < N; i++)
{
node[i].leftsum = add(node[i-].sum,node[i-].leftsum);
node[i].left = node[i-].left;
node[i].right = node[i-].right;
node[i].sum=add(node[i-].sum,node[i].leftsum);
if(node[i].right==node[i-].left&&node[i].right == ) node[i].sum = add(node[i].sum,"");
}
}
int main()
{
int n;
init();
while(~scanf("%d",&n)){
// printf("%s\n",node[n].sum);
cout<<node[n].sum<<endl;
}
return ;
}

大数加法模板

 string add(string s1,string s2){ //大数 s1 + s2
if(s1.length()<s2.length()){
string temp=s1;
s1=s2;
s2=temp;
}
for(int i=s1.length()-,j=s2.length ()-;i>=;i--,j--){
s1[i]=char(s1[i]+( j>= ? s2[j]-'' : ));
if(s1[i]-''>=) {
s1[i]=char( (s1[i]-'')%+'' );
if(i) s1[i-]++;
else s1=""+s1;
}
}
return s1;
}

hdu_1041(Computer Transformation) 大数加法模板+找规律的更多相关文章

  1. vijos - P1447开关灯泡 (大数模板 + 找规律 + 全然数 + python)

    P1447开关灯泡 Accepted 标签:CSC WorkGroup III[显示标签] 描写叙述 一个房间里有n盏灯泡.一開始都是熄着的,有1到n个时刻.每一个时刻i,我们会将i的倍数的灯泡改变状 ...

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

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

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

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

  4. Computer Transformation(规律,大数打表)

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

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

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

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

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

  7. hdu 5047 大数找规律

    http://acm.hdu.edu.cn/showproblem.php?pid=5047 找规律 信kuangbin,能AC #include <stdio.h> #include & ...

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

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

  9. hdu4952 Number Transformation (找规律)

    2014多校 第八题 1008 2014 Multi-University Training Contest 8 4952 Number Transformation Number Transform ...

随机推荐

  1. iOS UIAlertController中加入倒计时,输入框,Swift讲解

    一.倒计时 @interface ViewController () { UIAlertController *alertview; NSString * message; NSTimer * wai ...

  2. 【NOIP模拟】cut

    Description F大爷热爱切树.今天他找到一棵黑白树,不到两秒钟,F大爷就把这棵树切掉了.已知原先树上共n个点,每个点都是黑点或者白点,F大爷切去若干条边后,分成的若干个连通子树中每块恰有一个 ...

  3. LeetCode中的最大子串和问题(Maximum Subarray)

    问题描述: Find the contiguous subarray within an array (containing at least one number) which has the la ...

  4. php编码的一些小规范

    本文同时发表在https://github.com/zhangyachen/zhangyachen.github.io/issues/104 最近在整理线上的hhvm warning,虽然每天产生百万 ...

  5. xamarin android制作圆角边框

    xamarin android制作圆角边框 效果图如下: 关键代码: drawable文件夹新建shape_corner_down.xml <?xml version="1.0&quo ...

  6. Maven安装教程

    一.安装Maven及配置环境变量 1.Maven官网地址:http://maven.apache.org/download.cgi  下载apache-maven-3.5.0-bin.zip文件 2. ...

  7. angular4.0 配置打包路径以及资源文件404问题

    一.配置打包路径 配置打包路径,便于提交到SVN,不用每次都复制粘贴 在.angular-cli.json文件中修改"outDir"的路径,打包后的项目将发布到路径下 二.解决打包 ...

  8. 关于“System.Data.OleDb.OleDbException,外部数据库驱动程序 (1) 中的意外错误。”的解决方案

    网站之前运行一直很正常,但有一次用户在导入格式为xls的excel文件,发生了错误,跟踪错误后抛出如下的异常: 错误提示: 未处理System.Data.OleDb.OleDbException HR ...

  9. ionic2 开始第一个App(二)

    安装App指令:ionic start 你的项目文件夹名称 tabs 安装指令如: ionic start myApp tabs 安装时间有点长,耐心等待~ 进入myApp文件夹指令:cd myApp ...

  10. JAVA实现跳一跳辅助程序之虎啸龙吟

    前序: 今天有幸,看到2位博主的文章,在此表示感谢.自己也动手实现了一下. 实现原理 请参考博主 https://www.cnblogs.com/dongkuo/p/8285162.html 另感谢博 ...