您的位置:首页 > 其它

Codeforces#449 (Div. 2)C 字符串递归处理

2017-12-03 11:04 399 查看
题目地址:http://codeforces.com/contest/897/problem/C

C. Nephren gives a riddle

time limit per test2 seconds

memory limit per test256 megabytes

inputstandard input

outputstandard output

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

input

3

1 1

1 2

1 111111111111

output

Wh.

input

5

0 69

1 194

1 139

0 47

1 66

output

abdef

input

10

4 1825

3 75

3 530

4 1829

4 1651

3 187

4 584

4 255

4 774

2 474

output

Areyoubusy

Note

For the first two examples, refer to f0 and f1 given in the legend.

【题意】:

定义一个字符串f0,然后定义字符串fi与f(i-1)的递归关系,

然后询问字符串fn的第k个字符是什么,k>长度时输出‘.’

【分析】:

由题意第一感觉,递归即可。

可是赛时脑子很渣,由于n很大,大数据爆long long 一直没处理好,每过。

之后看了别人的代码觉悟了。其实当n大于53时,k再也达不到f(n)的大小,

所以n>53时,直接让f(n)=INF即可。。。(f(n)表示长度)

【代码】:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll f[101010];
char *f0="What are you doing at the end of the world? Are you busy? Will you save us?";
//75
char *s1="What are you doing while sending \"";
//34
char *s2="\"? Are you busy? Will you send \"";
//32
char *s3="\"?";
//2
char read(ll n,ll k)
{
if(k>f
)return '.';
if(n==0)return f0[k-1];

if(k<=34)return s1[k-1];//1 +
k-=strlen(s1);
if(k<=f[n-1])return read(n-1,k);

k-=f[n-1];
if(k<=strlen(s2))return s2[k-1];

k-=strlen(s2);
if(k<=f[n-1])return read(n-1,k);

k-=f[n-1];
if(k<=2)return s3[k-1];
}
int main()
{
f[0]=75;
f[1]=218;
for(int i=2;i<=55;i++)
f[i]=f[i-1]*2+68;
for(int i=55;i<100010;i++)
f[i]=f[53];
ll q,n,k;
cin>>q;
while(q--)
{
cin>>n>>k;
printf("%c",read(n,k));
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐