【题目来源】多校2014
【题目含义】开始时A = "^__^" (four characters), and B = "T.T" (three characters),根据A和B两个字符串来求字符串C,规则如下:
先运算 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^__^". 接着重复上述步骤。最后得到的字符串是无限长的。问题是C串中求第n个字符是什么(从第一个开始计算).
【题目分析】很明显该题是一个简单的DP问题,还运用到了斐波那契数列的一点知识。
【代码】
#include <iostream>
#include <cstdio>
#include <cstring>
#define mem(x) memset((x),0,sizeof((x)))
#define inf 0x7fffffff
#define MAXN 10+1000
using namespace std;
long long a[MAXN]={4,3};
#define M 10000000000000000000
#define MAXN_LL 0x7fffffffffffffffll
void init()
{
for(int i = 2; i <= 88; i++)
a[i] = a[i-1] + a[i-2];
a[89] = MAXN_LL;
}
int main()
{
//freopen("in.txt","r",stdin);
init();
long long n;
while(cin>>n){
while(n > 7){
int k = 0;
while(a[k++] < n);
n = n - a[k-2];
}
switch(n)
{
case 0:
case 4:
case 7:
cout<<"^";
break;
case 1:
case 3:
cout<<"T";
break;
case 2:
cout<<".";
break;
case 5:
case 6:
cout<<"_";
break;
default:
cout<<"error";
}
cout<<endl;
}
return 0;
}