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. android selector中使用shape

    <shape> <!-- 实心 -->     <solid android:color="#ff9d77"/> <!-- 渐变 --&g ...

  2. Struts2_总结

    还未学习的内容,如果到时候要用到,再去学.1.Lamda 表达式(很复杂,很少用)2.验证框架(默认验证方法 validation.方法开始前验证.开始后验证)3.UI标签(用的不多)4.类型转换中的 ...

  3. Coppermine-1.5.46 (Ubuntu 16.04.1)

      平台: Ubuntu 类型: 虚拟机镜像 软件包: coppermine-1.5.46 commercial content management coppermine media sharing ...

  4. web service 对外发布一个hello world接口(入门)

    1.写一个需要发布的接口 package com.hb; import javax.jws.WebParam; import javax.jws.WebService; @WebService pub ...

  5. Spark job执行流程消息图

    Spark job执行流程消息图 1.介绍

  6. PHP:将json数据放进html标签中的详细讲解

    1.在controller中调用某方法,得到最终的json数据.根据框架开发形式,将Json数据传入视图中 2.在视图中,我们放置一个hidden形式的标签,并获取到json数据 3.这时候,我们查看 ...

  7. 【PHP 基础类库】Prototype 原型版教学文章!

    前言 大家好我是:石不易,今天我为大家带来了PHP基础类库原型版的教学文章,至此本人的作品线已分为三大类,分别是:JavaScript前端框架(封装库).PHP模板引擎.以及PHP基础类库.该类库历时 ...

  8. IOS TableView代理设置 table的行高

    // 设置行高(每一行的高度一致) self.tableView.rowHeight = ; self.tableView.delegate = self; #pragma mark - 代理方法 / ...

  9. IOS 制作动画代码和 设置控件透明度

    方式1: //animateWithDuration用1秒钟的时间,执行代码 [UIView animateWithDuration:1.0 animations:^{ //存放需要执行的动画代码 s ...

  10. 问题 B: 投简历

    题目描述 小华历经12寒窗苦读,又经历4年大学磨砺,终于毕业了,随着毕业季的到来,找工作也日益紧张起来.由于要面试不同的公司,因此小华需要准备不同的简历.当然最基本的信息是必不可少的,基本信息:姓名. ...