ZOJ-Big string(服气思维)

Posted 余生漫漫浪

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ZOJ-Big string(服气思维)相关的知识,希望对你有一定的参考价值。

个人心得:我在分治上看到的,但是感觉跟分治没关系,一眼想到斐波那契数可以找到此时n的字符串,但是无法精确到字母,题解的思路

真是令人佩服,以BA为基准,然后只要此时的长度大于7那么必然可以减去最大的斐波那契数然后转换为基准,此时直接输出就好了。服气服气

题目:

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 above 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

1
2
4
8


Sample Output

T
.
^
T
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<cstring>
 5 #include<iomanip>
 6 #include<algorithm>
 7 using namespace std;
 8 #define maxi 0x7FFFFFFFFFFFFFFFLL
 9 long long x[100];
10 string base="T.T^__^";
11 void init(){
12    x[2]=10;
13    x[1]=7;
14    for(int i=3;i<100;i++)
15    {
16        x[i]=x[i-1]+x[i-2];
17    }
18 }
19 int main()
20 {
21    long long n;
22    init();
23    while(cin>>n){
24        while(n>7){
25         int i=0;
26         while(i<100&&x[i]<n)
27             i++;
28         n-=x[i-1];
29        }
30        cout<<base[n-1]<<endl;
31    }
32    return 0;
33 }

 



以上是关于ZOJ-Big string(服气思维)的主要内容,如果未能解决你的问题,请参考以下文章

201621123062《java程序设计》第九周作业总结

201621123037 《Java程序设计》第9周学习总结

Buy Tickets(线段树单点更新,逆向思维)

CSP核心代码片段记录

如何将代码片段存储在 mongodb 中?

学号:201521123116 《java程序设计》第八周学习总结