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. cocoapods管理以及常遇到的问题

    CocoaPods使用 安装成功啦,咱们来创建Podfile文件 //咱们先滚去项目的根目录,如果不会,你就先滚去看看shell命令教程吧 $ cd /Users/JamesGu/Desktop/Co ...

  2. c语言文件分割与合并

    一.综述 c语言操作文件通过文件指针FILE*,每个要操作的文件必须打开然后才能读写. 注意事项: @1分割与合并文件最好使用二进制模式即"rb"或"wb",这 ...

  3. javascript01

    手敲代码01 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <ti ...

  4. lesson - 12 Linux系统日常管理1

    监控系统状态 – w, vmstat命令w, uptimesystem load averages 单位时间段内活动的进程数 查看cpu的个数和核数vmstat 1vmstat 1 10vmstat各 ...

  5. java内存溢出问题

    相信有一定java开发经验的人或多或少都会遇到OutOfMemoryError的问题,这个问题曾困扰了我很长时间,随着解决各类问题经验的积累以及对问题根源的探索,终于有了一个比较深入的认识. 在解决j ...

  6. MicroPython之TPYBoard v102开发板控制OLED显示中文

    转载请以链接形式注明文章来源,公众号:MicroPython玩家汇 0x00前言 之前看到一篇文章是关于TPYBoardv102控制OLED屏显示的,看到之后就想尝试一下使用OLED屏来显示中文.最近 ...

  7. iOS开发系列

    因为最近面试了一些人,校招.初中级.高级.架构师,各种级别的,发现大家水平差异很大,有的高级的工程师很多问题都回答不上来,所以想梳理下iOS的知识点,写成一个系列,如果时间允许的话,会录制成视频放到网 ...

  8. window64 PHP ffmpeg详解简单上手 音频amr转mp3

    从网上找了一大堆关于window 64 ffmpeg的信息,都是又长又不关键,让人难消化. 我只要简单的amr转MP3格式而已. 终于搞明白.自己总结了下! 希望能帮助到喜欢言简意赅,一眼上手的同学. ...

  9. 《algorithms Unlocked》读书笔记3——计数排序

    <Algorithms Unlocked>是 <算法导论>的合著者之一 Thomas H. Cormen 写的一本算法基础,算是啃CLRS前的开胃菜和辅助教材.如果CLRS的厚 ...

  10. "软件随想录" 读书笔记

    人员管理: 三种方法: 军事化管理方法, 经济利益驱动法, 认同法. 军事化管理方法不行. 经济利益驱动法也不行. 认同法, 其中一条建议是一起干活的人一起吃饭. 但这种做法比较困难. 设计的作用 寸 ...