"Noi Question Bank" 9269:big string Super Strings

Source: Internet
Author: User

Portal: http://noi.openjudge.cn/ch0207/9269/

------------------------------------topic content--------------------------------------

9269:big String Super Strings

Total time limit: 10000ms single test point time limit: 1000ms memory limit: 131072kB

Describe

Fish in countless Oi competitions after the prison, realize a truth, often the easier the topic, the deeper the trap. As a result, fish created this topic.

Fish first gives two short strings of a= ' 4567 ' (4 characters), b= ' 123 ' (3 characters). Do the following repeatedly to get a long string of C.

(1) C=b+a (example: a= ' 4567 ', b= ' 123 ' c=b+a= ' 1234567 ')

(2) A=b b=c (above example a= ' 123 ' b= ' 1234567 ')

Please program to find the nth character of this long string.

---------

Input

The first line contains an integer n (1<=n<=10^9)

---------

Output

A single line that contains a character that represents the nth character of the long string.

---------

Sample input

9

Sample output

2

----------------------------------------Problem Solving-----------------------------------------

Let's look at the length change of a,b,c:

It can be found that the composition of this string is only a few characters 1,2,3,4,5,6,7,

And 4,5,6,7 only belong to ' 4567 ', and the only one is ' 123 ',

Then, but when the number of operations is singular, the end of the string "C" must be ' 4567 ' "Length 4"

But when the number of operations is even, the end of the string "C" must be ' 123 ' "Length 3"

--------------------------------------------

Ideas:

You can use recursion to find the character that you are looking for in 123 or 4567 of the first, you can find the output.


Code:

1  ProgramChaojizifuchuan;2 var3 N,tochange,tcd:longint;4//-----------------------------------------------------------------------------5 functionNeed (T1:longint): longint;//Several steps are required6 var7 Sum,xh,sum2,su:longint;8 begin9xh:=2; //Two steps are required by defaultTensum:=7; xh-1the string length of the step Onesum2:=Ten; //string length of XH step A    whileSum2<t1 Do//When the string length of the XH step is less than T1 -   begin -Inc (XH); //on the increase of one step thesu:=sum2; //Backup sum2 -sum2:=sum+sum2; //Increase sum2 -SUM:=SU; sum=sum2 at the previous step -   End; +   ift1<=7  Thenxh:=1; //if T1 is less than or equal to 7 only one step is required -tochange:=sum2; //Tochange is used to record the string length "global variable" of XH step at this time +Tcd:=sum; TCD is used to record this time xh-1The string length of the step "global variable" AExit (XH); //back to XH step at End; -//----------------------------------------------------------------------------- - procedureprintf (T2:char); - begin -Writeln (T2); //Output -Halt //terminating the main program in End; -//----------------------------------------------------------------------------- to proceduretry (len:longint); + var - Bu,total,last:longint; the c:string; * begin $   iflen<=7  Then begin//less than or equal to 7 o'clockPanax Notoginsengc:='1234567'; - printf (C[len]); the                      End +   Else begin//greater than 7 o'clock ABu:=need (len); //the number of steps required theTotal:=tochange; //string length when recording bu step +tochange:=0; //Restore Tochange -             ifOdd (BU) Thenlast:=4  $                   Elselast:=3; If the number of steps required is a singular '4567' At the end, if the even is '123' End $             ifLen>=total-last Then begin//if the last segment of the string -                                                 iflast=4  Thenc:='4567' -                                                    Elsec:='123'; //last record is the length of the final paragraph . theprintf (C[len-total+last]); //Output -                                             EndWuyi             Else begin theDec (BU); //this seems to erase Qaq . -TOTAL:=TCD; //Previous step length Wutcd:=0; //Restore TCD -Try (len-total);//continue try that lastend to Len segment "whose length is Len minus the length of the previous step" About                    End; $         End; -  - End; -//----------------------------------------------------------------------------- A begin +READLN (n); //Read in theTry (n); //Try - End.

Happy Mid-Autumn Festival Qaq----in 2016.9.15

"Noi Question Bank" 9269:big string Super Strings

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.