链接:http://codeforces.com/contest/897/problem/C
题意:字符串的递归。f0=What are you doing at the end of the world? Are you busy? Will you save us?
s1=What are you doing while sending "
s2="? Are you busy? Will you send "
s3="?
其中fi=s1+fi-1+s2+fi-1+s3;
输入q,n,k(1<=q<=10,0 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^18);q表示询问次数,n,k,表述fn中第k个字符;当k大于fn的长度输出‘.'。
输出fn中第k个字符。
注意:k非常的大,可以自己测试一下当n为多少的时候长度就超过1e18,之后的字符串长度就可以与此时的fn的长度一样。
1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long LL; 4 const int maxn=1e5+5; 5 char *f0="What are you doing at the end of the world? Are you busy? Will you save us?"; 6 ///75 7 char *s1="What are you doing while sending \""; 8 ///34 9 char *s2="\"? Are you busy? Will you send \""; 10 ///31 11 char *s3="\"?"; 12 ///2 13 ///fi=s1+fi-1+s2+fi-1+s3; 14 LL f[maxn]; 15 char get_(LL n,LL k) 16 { 17 if(k>f[n]) return '.'; 18 if(n==0) return f0[k-1]; 19 20 if(k<=strlen(s1)) return s1[k-1];///s1 21 22 k=k-strlen(s1); 23 if(k<=f[n-1]) return get_(n-1,k);///fi-1 24 25 k=k-f[n-1]; 26 if(k<=strlen(s2)) return s2[k-1];///s2 27 28 k=k-strlen(s2); 29 if(k<=f[n-1]) return get_(n-1,k);///fi-1 30 31 k=k-f[n-1]; 32 if(k<=strlen(s3)) return s3[k-1];///s3 33 } 34 35 int main() 36 { 37 f[0]=75; 38 f[1]=218; 39 for(int i=2;i<=55;i++) 40 f[i]=f[i-1]*2+68; 41 for(int i=55;i<=100000;i++) 42 f[i]=f[54];///2e18 43 ///cout<<f[54]; 44 LL Q,N,K; 45 char ans[maxn]; 46 cin>>Q; 47 int i=0; 48 while(Q--) 49 { 50 cin>>N>>K; 51 cout<<get_(N,K); 52 } 53 return 0; 54 }