标签:style color os strong io for ar line
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
题意:开始时有两个字符串,A = "^__^" (four characters), B = "T.T" (three characters),然后重复执行C=BA,A=B,B = C,问第n个字符是什么。
分析:因为最终的字符串是从前往后递推出来的,所以再求解时,我们可以把这个过程逆过去,直到字符串的长度不超过7,输出即可。
#include<iostream> #include<string> using namespace std; typedef long long LL; LL a[95]; //保存字符串的长度 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, a+89, n) - a; n -= a[pos-1]; } cout << C[n-1] << endl; } return 0; }
ZOJ 1633 Big String,布布扣,bubuko.com
标签:style color os strong io for ar line
原文地址:http://blog.csdn.net/lyhvoyage/article/details/38350287