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. zepto的返回顶部scrollTop的动画解决方法

    写移动端的时候,引入的zepto.js里的animate不包括scrollTop,所以返回顶部的时候,没有动画的效果.这里我使用的是setInterval的方法.代码详情如下 <!DOCTYPE ...

  2. 转 - .net/c# 使用RabbitMQ

    背景 最近需要用C#写一个Adapter来做数据传输,合作方使用的是RabbitMQ,所以我这边也要跟着写写... 在网上搜索了一些,发现园子里的这篇写的还是非常好的.虽然有点老了,我自己用的是最新的 ...

  3. weex Mac开发环境

    安装: 1.java的jdk下载和安装 1-1.下载.安装:省略 1-2.配置 第一步:命令行内输入touch .bash_profile命令,生成.bash_profile的隐藏配置文件,用于配置j ...

  4. 百度图表插件echart简单应用,简单配置一些要显示的样式及种类

    从echart官网下载js,然后引入jq即可运行.足够简单应用了 关键词:echart控制:图标标题.数据标题.折线图.柱状图切换按钮.恢复刷新图表按钮.保存为图片按钮.坐标系控制.坐标数据.坐标倾斜 ...

  5. rsync服务器的搭建

    Rsync(remote synchronize)是一个远程数据同步工具,简要的概括就是主机于主机之间的文件目录数据的一个同步.下面就是rsync服务器的搭建过程.    系统环境 平台:Centos ...

  6. Odwiedziny[POI 2015]

    题目描述 给定一棵n个点的树,树上每条边的长度都为1,第i个点的权值为a[i]. Byteasar想要走遍这整棵树,他会按照某个1到n的全排列b走n-1次,第i次他会从b[i]点走到b[i+1]点,并 ...

  7. PHP动态图像处理

    相关代码见:https://www.github.com/lozybean/learn_www/ 目录 1. 画布管理:     imagecreate():创建一个基于调色板的画布,指定画布的长.宽 ...

  8. JavaScript ES6中export及export default的区别

    相信很多人都使用过export.export default.import,然而它们到底有什么区别呢? 在JavaScript ES6中,export与export default均可用于导出常量.函 ...

  9. 如何在 iOS 真机运行 Appium

    使用 gui 启动的 appium 1.2.2 也会有这个问题,所以你要把 deviceconsole 复制到 /Applications/Appium.app/Contents/Resources/ ...

  10. hook 虚表

    PVOID* GetVtpl(PVOID lpThis, int nIndex){  return *(PVOID**)lpThis + nIndex;} PVOID HookVtpl(PVOID*  ...