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
Note

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

思路: 字符串长度的递推式:f[n]=2*f[n-1]+l1+l2+l3,然后分成5段来找所求字母,l1-(s[n-1])-l2-(s[n-1])-l3.

代码:

 #include<bits/stdc++.h>
#define db double
#define ll long long
#define vec vector<ll>
#define Mt vector<vec>
#define ci(x) scanf("%d",&x)
#define cd(x) scanf("%lf",&x)
#define cl(x) scanf("%lld",&x)
#define pi(x) printf("%d\n",x)
#define pd(x) printf("%f\n",x)
#define pl(x) printf("%lld\n",x)
//#define rep(i, x, y) for(int i=x;i<=y;i++)
const int N = 1e6 + ;
const int mod = 1e9 + ;
const int MOD = mod - ;
const db eps = 1e-;
const db PI = acos(-1.0);
using namespace std;
string s0="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="\"?"; ll f[N]={,,,,};
int l1,l2,l3;
void init()
{
for(int i=;;i++){
ll x=f[i-]*+;
if(x>1e18) break;
f[i]=f[i-]*+;
}
}
char dfs(ll n,ll k)
{
if(!n) return k<=?s0[k-]:'.';
if(k<=l1) return s1[k-];//第一段
k-=l1;
if(k<=f[n-]||!f[n-]) return dfs(n-,k);//在范围内或者当前字符串长度远超目标位置
k-=f[n-];
if(k<=l2) return s2[k-];//s2的范围内
k-=l2;
if(k<=f[n-]||!f[n-]) return dfs(n-,k);
k-=f[n-];
return k<=l3?s3[k-]:'.';//最后一段 }
int main(){
init();
ll n,k;
int t;
ci(t);
l1=(int)s1.size(),l2=(int)s2.size(),l3=(int)s3.size();
while(t--)
{
cl(n),cl(k);
putchar(dfs(n,k));
}
return ;
}

Codeforces Round #449 (Div. 2) C. DFS的更多相关文章

  1. Codeforces Round #449 (Div. 2)

    Codeforces Round #449 (Div. 2) https://codeforces.com/contest/897 A #include<bits/stdc++.h> us ...

  2. Codeforces Round #449 (Div. 2)ABCD

    又掉分了0 0. A. Scarborough Fair time limit per test 2 seconds memory limit per test 256 megabytes input ...

  3. Codeforces Round #381 (Div. 2) D dfs序+树状数组

    D. Alyona and a tree time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  4. Codeforces Codeforces Round #383 (Div. 2) E (DFS染色)

    题目链接:http://codeforces.com/contest/742/problem/E 题意: 有一个环形的桌子,一共有n对情侣,2n个人,一共有两种菜. 现在让你输出一种方案,满足以下要求 ...

  5. Codeforces Round #290 (Div. 2) B (dfs)

    题目链接:http://codeforces.com/problemset/problem/510/B 题意:判断图中是否有某个字母成环 思路:直接dfs就好了,注意判断条件:若下一个字母与当前字母相 ...

  6. Codeforces Round #222 (Div. 1) Maze —— dfs(连通块)

    题目链接:http://codeforces.com/problemset/problem/377/A 题解: 有tot个空格(输入时统计),把其中k个空格变为wall,问怎么变才能使得剩下的空格依然 ...

  7. Codeforces Round #428 (Div. 2) C. dfs

    C. Journey time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...

  8. Codeforces Round #321 (Div. 2) C dfs处理(双向边叶子节点的判断)

    C. Kefa and Park time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  9. Codeforces Round #449 (Div. 2) B. Chtholly's request【偶数位回文数】

    B. Chtholly's request time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

随机推荐

  1. Spring课程 Spring入门篇 4-1 Spring bean装配(下)之bean定义及作用域注解实现

    课程链接: 1 概述 2 代码演练 3 代码解析 1 概述 1.1 bean注解相关 a context:component-scan标签使用 问:该标签的作用是什么? 答:该标签作用是支持注解,在x ...

  2. (生产)animate.css 动画库

    官网:https://daneden.github.io/animate.css/ Animate.css是一个有趣的,跨浏览器的css3动画库 用法 首先引入animate css文件:    &l ...

  3. Android 设置软键盘搜索键以及监听搜索键点击事件

    如图所示,有时候为了布局美观,在搜索时没有搜索按钮,而是调用软件盘上的按钮.调用的实现只需要在XML在输入框中加入android:imeOptions="actionSearch" ...

  4. python-gearman使用

    yum -y install gearmand chkconfig gearmand on && /etc/init.d/gearmand start # /etc/sysconfig ...

  5. 有趣的回文数(Palindrome number)

    文章转自http://blog.163.com/hljmdjlln@126/blog/static/5473620620120412525181/ 做LC上的题"Palindrome num ...

  6. Docker build 安装报错, Could not open requirments file: [Errno 2] No such file or directory:'requirements.txt'

    docker安装教程 https://docs.docker.com/get-started/part2/#build-the-app 相关帖子 https://stackoverflow.com/q ...

  7. leetcode: 树

    1. sum-root-to-leaf-numbers Given a binary tree containing digits from0-9only, each root-to-leaf pat ...

  8. ssh key一键自动化生成公钥私钥,并自动分发上百服务器免密码交互

    题记:由于工作需要管理大量服务器,所以需要配公钥实现免密登录. ssh批量分发可以一键执行这个操作,但是使用ssh分发服务还需要对各个服务器进行.ssh/id_dsa.pub公钥上传,密码验证.所以需 ...

  9. php无法保存SESSION问题总汇

    昨天客户又过来说网站的问题,说的也都是些毛毛雨的东西,管理那么多网站,再有这么些客户的存在,本人也是累了,但当登录后台的时候突然发现后台登录不了,查看了一下验证码服务器端的session为空值,之前登 ...

  10. 2017.10.10 java中的继承与多态(重载与重写的区别)

    1. 类的继承 继承是面向对象编程技术的主要特征之一,也是实现软件复用的重要手段,使用继承特性子类(subclass) 可以继承父类(superclass)中private方法和属性,继承的目的是使程 ...