Codeforces Round #449 div2 C(递归求解)

来源:互联网 发布:pdf.js ajax 编辑:程序博客网 时间:2024/06/09 22:11

Description

What are you doing at the end of the world? Are you busy? Will you save us?
Nephren is playing a game with little leprechauns.

She gives them an infinite array of strings, f0… ∞.

f0 is “What are you doing at the end of the world? Are you busy? Will you save us?”.

She wants to let more people know about it, so she defines fi =  “What are you doing while sending “fi - 1”? Are you busy? Will you send “fi - 1”?” for all i ≥ 1.

For example, f1 is

“What are you doing while sending “What are you doing at the end of the world? Are you busy? Will you save us?”? Are you busy? Will you send “What are you doing at the end of the world? Are you busy? Will you save us?”?”. Note that the quotes in the very beginning and in the very end are for clarity and are not a part of f1.

It can be seen that the characters in fi are letters, question marks, (possibly) quotation marks and spaces.

Nephren will ask the little leprechauns q times. Each time she will let them find the k-th character of fn. The characters are indexed starting from 1. If fn consists of less than k characters, output ‘.’ (without quotes).

Can you answer her queries?

Input

The first line contains one integer q (1 ≤ q ≤ 10) — the number of Nephren’s questions.

Each of the next q lines describes Nephren’s question and contains two integers n and k (0 ≤ n ≤ 105, 1 ≤ k ≤ 1018).

Output

One line containing q characters. The i-th character in it should be the answer for the i-th query.

Examples

input31 11 21 111111111111outputWh.input50 691 1941 1390 471 66outputabdefinput104 18253 753 5304 18294 16513 1874 5844 2554 7742 474outputAreyoubusy

题目大意

fi =  “What are you doing while sending “fi - 1”? Are you busy? Will you send “fi - 1”?” 如题,根据fi的定义求fn的第k个字符是什么

解题思路

递归求解

代码实现

#include<bits/stdc++.h>using namespace std;typedef long long ll;ll len[60];int maxx,len0,len1,len2,len3;char s0[]="What are you doing at the end of the world? Are you busy? Will you save us?";char s1[]="What are you doing while sending \"";char s2[]="\"? Are you busy? Will you send \"";char s3[]="\"?";void init(){    len0=strlen(s0);    len1=strlen(s1);    len2=strlen(s2);    len3=strlen(s3);    len[0]=len0;    maxx=0;    while(len[maxx]<1e18+5)    {        maxx++;        len[maxx]=len1+len[maxx-1]+len2+len[maxx-1]+len3;    }}char dfs(int n,ll k){    if(n<=maxx&&k>len[n]) return '.';    if(n==0) return s0[k-1];    if(k<=len1) return s1[k-1];    k-=len1;    if(n>maxx||k<=len[n-1]) return dfs(n-1,k);    k-=len[n-1];    if(k<=len2) return s2[k-1];    k-=len2;    if(n>maxx||k<=len[n-1]) return dfs(n-1,k);    k-=len[n-1];    return s3[k-1];}int main(){    ios::sync_with_stdio(false);    init();    int T,n;    ll k;    cin>>T;    while(T--)    {        cin>>n>>k;        cout<<dfs(n,k);    }    return 0;}