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 }



Codeforces #449 div2 C题的更多相关文章

  1. Codeforces #449 Div2 D

    #449 Div2 D 题意 交互式类题目. 起始有 n 张纸,会给出 m 次数字 p (\(1 \leq p \leq c\)),每次可选择一张纸,并在纸上写上这个数字,如果纸上已经存在数字,会覆盖 ...

  2. codeforces #262 DIV2 B题 Little Dima and Equation

    题目地址:http://codeforces.com/contest/460/problem/B 这题乍一看没思路.可是细致分析下会发现,s(x)是一个从1到81的数,不管x是多少.所以能够枚举1到8 ...

  3. codeforces 260 div2 C题

    C题就是个dp,把原数据排序去重之后得到新序列,设dp[i]表示在前i个数中取得最大分数,那么: if(a[i] != a[i-1]+1)   dp[i] = cnt[a[i]]*a[i] + dp[ ...

  4. codeforces 260 div2 B题

    打表发现规律,对4取模为0的结果为4,否则为0,因此只需要判断输入的数据是不是被4整出即可,数据最大可能是100000位的整数,判断能否被4整出不能直接去判断,只需要判断最后两位(如果有)或一位能否被 ...

  5. Codeforces #541 (Div2) - E. String Multiplication(动态规划)

    Problem   Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...

  6. Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)

    Problem   Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...

  7. 【Codeforces #312 div2 A】Lala Land and Apple Trees

    # [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...

  8. Codeforces #180 div2 C Parity Game

    // Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...

  9. Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)

    Problem   Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...

  10. Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)

    Problem   Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...

随机推荐

  1. .NET6.0实现IOC容器

    .NET6.0实现IOC容器 IOC的作用这里省略-只对如何使用进行说明. 1. 创建一个.NET6应用程序 这里使用 .NET6.0 WebAPI 应用 2. 声明接口 public interfa ...

  2. 微信小程序隐私保护协议修改方法 uniapp

    微信隐私保护协议指南 一天天没事闲的   01 在manifest.json 中添加一行 "__usePrivacyCheck__" : false   02 自定义一个弹窗组件 ...

  3. tarjan强连通分量

    int scc[N],sc;//结点i所在scc的编号 int sz[N]; //强连通i的大小 //dfn(u)为搜到结点u时的次序编号 //low(u)为u或u的子树能够追溯到的最早的栈中节点的次 ...

  4. 前端三件套系例之JS——JS的BOM操作、JS的DOM操作

    文章目录 1 JS的BOM操作 1.介绍 2.window对象 2-1 代码 3.window的子对象 3-1 navigator对象(了解即可) 3-2 screen对象(了解即可) 3-3 his ...

  5. C#归并排序算法

    前言 归并排序是一种常见的排序算法,它采用分治法的思想,在排序过程中不断将待排序序列分割成更小的子序列,直到每个子序列中只剩下一个元素,然后将这些子序列两两合并并排序,最终得到一个有序的序列. 归并排 ...

  6. 使用 Helm 管理应用的一些 Tips

    背景 Helm 是一个 Kubernetes 的包管理工具,有点类似于 Mac 上的 brew,Python 中的 PIP:可以很方便的帮我们直接在 kubernetes 中安装某个应用. 比如我们可 ...

  7. Go包介绍与初始化:搞清Go程序的执行次序

    Go包介绍与初始化:搞清Go程序的执行次序 目录 Go包介绍与初始化:搞清Go程序的执行次序 一.main.main 函数:Go 应用的入口函数 1.1 main.main 函数 1.2 main.m ...

  8. Hello-FPGA CoaXPress 2.0 FPGA HOST IP Core PCIe Demo User Manual

    目录 1 说明 4 2 设备连接 7 3 VIVADO FPGA工程 8 4 调试说明 9 图 1‑1 资料目录 4 图 1‑2 VIVADO工程目录结构 5 图 1‑3 VS软件工程目录 5 图 1 ...

  9. TOBO

    然而并不会做. 最后就照着题解码了一遍/kk 真的好长啊.看时间就知道写了多久... upd in 2022: 我现在已经找不到原题面是什么了( 不过感觉把这样一篇不算题解的东西放进"题解& ...

  10. k8s Redis安装部署

    一.文档简介 作者:lanjiaxuan 邮箱:lanheader@163.com 博客地址:https://www.cnblogs.com/lanheader/ 更新时间:2021-07-09 安装 ...