Appoint description:
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?
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
//这题意思是
1 01 0
2 1001 1
3 01101001 1
1->01 0->10
就这么一直变下去,问 n 步之后,有多少个相邻的 0
我是先输出模拟了大概 8 项找出了规律,然后。。。wa
因为数据太大,long long 也存不下
然后用字符串,当做大数处理,就可以了,注意一些细节问题,代码里有

1 /* 2 //EEE 3 #include <stdio.h> 4 #include <string.h> 5 6 char ch[10][1200]; 7 8 int main() 9 { 10 strcpy(ch[0],"01"); 11 12 for (int i=1;i<10;i++) 13 { 14 int k=0; 15 int len=strlen(ch[i-1]); 16 for (int j=0;j<len;j++) 17 { 18 if (ch[i-1][j]=='0') 19 { 20 ch[i][k++]='1'; 21 ch[i][k++]='0'; 22 } 23 else 24 { 25 ch[i][k++]='0'; 26 ch[i][k++]='1'; 27 } 28 } 29 ch[i][k]=' '; 30 } 31 for (int i=0;i<10;i++) 32 { 33 34 int sum=0; 35 int len =strlen(ch[i]); 36 for (int j=0;j<len-1;j++) 37 { 38 if (ch[i][j]=='0'&&ch[i][j+1]=='0') 39 sum++; 40 } 41 //printf("%s ",ch[i]); 42 printf("%d ",sum); 43 } 44 return 0; 45 } 46 */ 47 48 #include <stdio.h> 49 #include <string.h> 50 #include <math.h> 51 #include <algorithm> 52 using namespace std; 53 54 char num[1005][500]; 55 char str[500]; 56 57 char *add(char s[]) 58 { 59 memset(str,0,sizeof(str)); 60 61 int i; 62 int len=strlen(s); 63 for (i=0;i<len;i++) 64 s[i]-='0'; 65 reverse(s,s+len); 66 67 for (i=0;i<len;i++) 68 { 69 str[i]+=s[i]*2; 70 if (i==0) str[i]++; 71 72 if (str[i]>=10) 73 { 74 str[i]-=10; 75 str[i+1]++; 76 } 77 78 } 79 while (str[i]!=0) i++; 80 str[i]='