ZOJ 1633 Big String

Source: Internet
Author: User

ZOJ 1633 Big String

Big String Time Limit: 2 Seconds Memory Limit: 65536 KB We will construct an infinitely long string from two short strings: A = "^__ ^" (four characters), and B = "T.T" (three characters). Repeat the following steps:
    Concatenate A after B to obtain a new string C. for example, if A = "^__ ^" and B = "T.T", then C = BA = "T.T ^__ ^ ". let A = B, B = C -- as the example abve A = "T.T", B = "T.T ^__ ^ ". your task is to find out the n-th character of this infinite string.


    Input

    The input contains multiple test cases, each contains only one integer N (1 <= N <= 2 ^ 63-1). Proceed to the end of file.


    Output

    For each test case, print one character on each line, which is the N-th (index begins with 1) character of this infinite string.


    Sample Input

    1248


    Sample Output

    T.^T
     
     
    Start with two strings, A = "^__ ^" (four characters), B = "T.T" (three characters), and then re-Execute C = BA, A = B, B = C. Ask what the nth character is.
     
     
    Analysis: because the final string is recursive from the past to the future, when solving the problem, we can reverse the process until the length of the string does not exceed 7, and the output is enough.
     
     
    # Include
       
        
    # Include
        
         
    Using namespace std; typedef long LL; LL a [95]; // Save the string length int main () {string C = "T.T ^__ ^ "; a [0] = 4; a [1] = 3; int I; for (I = 2; I <90; I ++) a [I] = a [I-1] + a [I-2]; LL n; while (cin> n) {while (n> 7) {int pos = lower_bound (, a + 89, n)-a; n-= a [pos-1];} cout <C [n-1] <endl;} return 0 ;}
        
       


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.