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.

题目大意:
就是给你q组数据,每一组有两个数,一个是第n句话,一个是这个第n句话中的第k个字母,求出这个字母。
给你第0句话和第一句话,让你进行递归搜索。
思路:
这个是看了很多题解,比较简单的一种
就是无论是第几句话,都分成五个部分,第一个就是双引号前面的,第二个是双引号中间的,第三个是第一个双引号后面
第二个双引号前面的,第四个是第二个双引号,第五个是第二个双引号后面的。
根据k判断它在这五个部分中的哪一个,找到后就进行定位输出。
具体:
先写一个长度函数,根据n句话判断它的长度,因为当n==55,len[n]==5e18了,所以就不需要往后算,而且也算不了。
因为再往后就超出范围了。
为什么不用算呢?因为这个是递归,而且k范围是1e18,所以不会有k>len[55]的情况出现。所以在n>=55,k都会在第一个
输出或者第二个部分进入下一个dfs。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
using namespace std;
typedef long long ll;
char f0[]="What are you doing at the end of the world? Are you busy? Will you save us?";
char f1[]="What are you doing while sending \"\"? Are you busy? Will you send \"\"?";
const int maxn=1e5+10;
const ll inf=1e18; ll len[maxn];
void init()
{
len[0]=strlen(f0);
int l=strlen(f1);
for(int i=1;i<=55;i++) len[i]=2*len[i-1]+l;
for(int i=56;i<=100000;i++) len[i]=len[55];
} char dfs(int n,ll k)
{
if(n==0)
{
if(k<len[0]) return f0[k];
return '.';
}
if(k<34) return f1[k];
k-=34;
if(k<len[n-1]) return dfs(n-1,k);
k-=len[n-1];
if(k<32) return f1[k+34];
k-=32;
if(k<len[n-1]) return dfs(n-1,k);
k-=len[n-1];
if(k<2) return f1[k+66];
return '.';
} int main()
{
int q;
scanf("%d",&q);
int n;
ll k;
init();
while(q--)
{
scanf("%d%I64d",&n,&k);
k--;//因为数组原因
char ans=dfs(n,k);
putchar(ans);
}
return 0;
}

  

寒假特训——搜索——H - Nephren gives a riddle的更多相关文章

  1. Codeforces Round #449 [ C/A. Nephren gives a riddle ] [ D/B. Ithea Plays With Chtholly ]

    PROBLEM C/A. Nephren gives a riddle 题 http://codeforces.com/contest/896/problem/A codeforces 896a 89 ...

  2. CodeForces - 896A Nephren gives a riddle

    A. Nephren gives a riddle time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  3. CF&&CC百套计划1 Codeforces Round #449 A. Nephren gives a riddle

    http://codeforces.com/contest/896/problem/A 第i个字符串嵌套第i-1个字符串 求第n个字符串的第k个字母 dfs #include<map> # ...

  4. Gym 101655:2013Pacific Northwest Regional Contest(寒假自训第13场)

    A .Assignments 题意:给定距离D,以及N个飞机的速度Vi,单位时间耗油量Fi,总油量Ci.问有多少飞机可以到达目的地. 思路:即问多少飞机满足(Ci/Fi)*Vi>=D  ---- ...

  5. Gym101986: Asia Tsukuba Regional Contest(寒假自训第12场)

    A .Secret of Chocolate Poles 题意:有黑白两种木块,黑色有1,K两种长度: 白色只有1一种长度,问满足黑白黑...白黑形式,长度为L的组合种类. 思路:直接DP即可. #i ...

  6. 寒假特训——I - Fair

    Some company is going to hold a fair in Byteland. There are nn towns in Byteland and mm two-way road ...

  7. Gym 101889:2017Latin American Regional Programming Contest(寒假自训第14场)

    昨天00.35的CF,4点才上床,今天打的昏沉沉的,WA了无数发. 题目还是满漂亮的. 尚有几题待补. C .Complete Naebbirac's sequence 题意:给定N个数,他们在1到K ...

  8. Gym.102006:Syrian Collegiate Programming Contest(寒假自训第11场)

    学习了“叙利亚”这个单词:比较温和的一场:几何的板子eps太小了,坑了几发. A .Hello SCPC 2018! 题意:给定一个排列,问它是否满足,前面4个是有序的,而且前面4个比后面的都小. 思 ...

  9. Gym.101955: Asia Shenyang Regional Contest(寒假自训第10场)

    C.Insertion Sort 题意:Q次询问,每次给出N,M,Mod,问你有多少种排列,满足前面M个数字排序之后整个序列的LIS>=N-1. 思路:我们把数字看成[1,M],[N-M+1,N ...

随机推荐

  1. ls 指令的介绍

    每个文件在linux下面都会记录许多的时间参数, 其实是有三个主要的变动时间,那么三个时间的意义是什么呢? modification time (mtime) : 当该文件的“内容数据”变更时,就会更 ...

  2. PHP定界符eof 的使用

    PHP是一个Web编程语言,在编程过程中难免会遇到用echo来输出大段的html和javascript脚本的情况,如果用传统的输出方法 ——按字符串输出的话, 肯定要有大量的转义符来对字符串中的引号等 ...

  3. 30.QT-渐变之QLinearGradient、 QConicalGradient、QRadialGradient

    渐变有三种:QLinearGradient.QConicalGradient . QRadialGradient 它们都有一个QGradient父类 QGradient父类的常用公共函数有: void ...

  4. 你所不知道的JSON.stringify

    译者按: 老司机们,你知道JSON.stringify还有第二个和第三个可选参数吗?它们是什么呢? 原文: What you didn’t know about JSON.Stringify 译者: ...

  5. react学习(四)之设置 css样式 篇

    react中设置css样式 方法一: 行内样式:使用{{  }},与正常jsx中插入js代码不一样,这里需要两个括号. <div style={ { float: 'right',} }> ...

  6. 通过css3实现的动画导航菜单代码

    用css3样式实现的滑动导航菜单,html代码如下 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" &quo ...

  7. 洛谷P4591 [TJOI2018]碱基序列(hash dp)

    题意 题目链接 Sol \(f[i][j]\)表示匹配到第\(i\)个串,当前在主串的第\(j\)个位置 转移的时候判断一下是否可行就行了.随便一个能搞字符串匹配的算法都能过 复杂度\(O(|S| K ...

  8. iOS----------导航栏的正确隐藏方式

    第一种做法 -注意这里一定要用动画的方式隐藏导航栏,这样在使用滑动返回手势的时候效果最好,和上面动图一致.这样做有一个缺点就是在切换tabBar的时候有一个导航栏向上消失的动画. - (void)vi ...

  9. mac 下 ipython+notebook

    python做数据分析相关的工具的安装和配置,以及numpy的入门 为什么要用PYTHON来做数据分析 MATLAB R语言,语法类似C语言,但是它在语义上是函数设计语言,也是开源的. python ...

  10. JHipster生成微服务架构的应用栈(三)- 业务微服务示例

    本系列文章演示如何用JHipster生成一个微服务架构风格的应用栈. 环境需求:安装好JHipster开发环境的CentOS 7.4(参考这里) 应用栈名称:appstack 认证微服务: uaa 业 ...