Computer transformationTime
limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 6543 Accepted Submission (s): 2378
Problem Descriptiona sequence consisting of one digit, the number 1 is initially written into a computer. At all successive time step, the computer simultaneously tranforms each digit 0 to the sequence 1 0 and each digit 1 in To 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 would appear in the sequence after n steps?
Inputevery input Line contains one natural number N (0 < n≤1000).
Outputfor each input n print the number of consecutive zeroes pairs that would appear in the sequence after n steps.
Sample Input
23
Sample Output
11
Sourcesoutheastern Europe 2005
recommendjgshining | We have carefully selected several similar problems for you:1006 1030 1032 1007 1143
First explain the topic: the approximate meaning of the topic is very simple, that is, the computer has an initial number 1, all the following rules and operations starting from 1, and then each generation of a transformation, the law of the transformation is as follows in this series all 1 transform into 01, all 0 into 10, so that may not be clear, Starting from 1, the next time you get a 1->01, and then the next time you get 1001 (last 0->10,1->01) and then you get 01101001, and so on .... Ask you how many groups of 00 have been transformed by N times! (consequitive meaning continuous, the same meaning!) )
Reference Netizen: Starry Night & Eternal Reasoning:
00 can only be pushed from 01, i.e. 01->1001->00
01 can only be pushed from 1, 00, or 1->01,00->1010->01.
Now set A[n] represents the number of 1 n seconds,
B[n] represents the number of 00 N seconds,
C[n] represents the number of 01 n seconds,
By the 0,1, a second will produce a 1,
So a[n+1]=2^n ..... 0 seconds 1 Number, 1 seconds 2*1 number, 2 seconds 2*1*2 number, ... n seconds 2*1*2*2*2..*2 number =2^n.
B[n+1]=c[n];
C[n+1]=a[n]+b[n],
So b[n]=c[n-1]=a[n-2]+b[n-2]=2^ (n-3) +b[n-2].
In fact, to write a few more examples can find another law b[n]=2*b[n-2]+b[n-1].
Note that the larger number is added.
/* * Based on recursion: b[n]=2*b[n-2]+b[n-1] */import java.io.*;import java.math.biginteger;import java.util.*;p ublic class Main{ public static void Main (string[] args) {//TODO auto-generated method Stubscanner input = new Scanner (system.in); BigInteger a[] = new biginteger[1001]; BigInteger b[] = new Biginteger[1001];a[0] = biginteger.one;b[2] = biginteger.one;b[0] = biginteger.zero;b[1] = BigInteger . zero;for (int i = 1; i < 1001; i++) {A[i] = a[i-1].multiply (biginteger.valueof (2)); This is a[i] but here the a[i]=2^ (i-2) if (I >= 3) //So the following count B[i] when I want to subtract a 1{b[i] = A[i-3].add (b[i-2]); }} while (Input.hasnext ()) {int n = input.nextint (); System.out.println (B[n]);}}
Hdu-1041-computer Transformation (regular && large number of questions)