Codeforces #449 div2 C题

C. Nephren gives a riddle
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard 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


题目大意:fi表示第i个字符串,输入q次询问,再输入n,k;输出fn的第k个字符。如果k大于fn的长度,那么就输出'.'。

解题思路:思维题,字符串很长,不能直接dfs,只能从长度入手,判断字符在fi字符串。

因为长度倍增,所以f53的时候差不多就超过了输入的最大值,n大于53的时候在dfs特判下就行。

AC代码:
 1 #include<iostream>
 2 #include<bits/stdc++.h>
 3 #include<stdio.h>
 4 #define ll long long
 5 #define MAX 1e18
 6 using namespace std;
 7 ll a[100500];
 8 string s0,s1,s2,s3;
 9 ll len1,len2,len3,len0;
10 ll most;
11 char dfs(ll n,ll k){
12     if(n==0){
13         return s0[k-1];
14     }
15     if(k<=len1){
16         return s1[k-1];
17     }
18     if(k<=len1+a[n-1]||n>most){  //特判一下
19         return dfs(n-1,k-len1);
20     }
21     if(k<=len1+a[n-1]+len2){
22         return s2[k-(len1+a[n-1])-1];
23     }
24     if(k<=len1+a[n-1]+len2+a[n-1]){
25         return dfs(n-1,k-(len1+a[n-1]+len2));
26     }
27     return s3[k-(len1+a[n-1]+len2+a[n-1])-1];
28 }
29 int main(){
30     s0="What are you doing at the end of the world? Are you busy? Will you save us?";
31     s1="What are you doing while sending \"";
32     s2="\"? Are you busy? Will you send \"";
33     s3="\"?";
34     len0=s0.length();
35     len1=s1.length();
36     len2=s2.length();
37     len3=s3.length();
38     a[0]=len0;
39     for(int i=1;i<60;i++){
40         ll s=len1+a[i-1]+len2+a[i-1]+len3;
41         if(s>MAX){
42             most=i;  //most==i,如果是i-1就会RE
43             break;
44         }
45         else a[i]=s;
46     }
47     int q;
48     cin>>q;
49     while(q--){
50         ll n,k;
51         cin>>n>>k;
52         if(n<=most&&k>a[n]){
53             cout<<'.';
54         }else{
55             cout<<dfs(n,k);
56         }
57     }
58     cout<<endl;
59     return 0;
60 }

 



posted @ 2017-12-08 10:03  ISGuXing  阅读(166)  评论(0编辑  收藏  举报