寒假特训——搜索——H - Nephren gives a riddle

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

31 11 21 111111111111

Output

Wh.

Input

50 691 1941 1390 471 66

Output

abdef

Input

104 18253 753 5304 18294 16513 1874 5844 2554 7742 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;
}

  

原文地址:https://www.cnblogs.com/EchoZQN/p/10354669.html

时间: 2024-07-30 14:00:45

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

CDZSC_2015寒假新人(4)——搜索 H

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description Hiking in the mountains is seldom an easy task for most people, as it is extremely easy to get lost during the trip. Recently Green has decided to go on a hiking

Gym.101908 Brazil Subregional Programming Contest(寒假自训第六场)

这几天失眠时间都不太够,室友太会折腾了,感觉有点累,所以昨天的题解也没写,看晚上能不能补起来. B . Marbles 题意:给定N组数(xi,yi),玩家轮流操作,每次玩家可以选择其中一组对其操作,可以把它减去一个数,或同时减去一个数,当玩家操作后出现了(0,0)则胜利. 思路:注意这里是出现(0,0)胜,而不是全都是(0,0)胜,所以我们不能简单的球sg,最后异或得到答案. 但是我们转化一下,如果玩家面对的全是(1,2) 或(2,1),则他胜利,那么我们可以以这两个状态为起点得到sg函数,就

寒假特训——I - Fair

Some company is going to hold a fair in Byteland. There are nn towns in Byteland and mm two-way roads between towns. Of course, you can reach any town from any other town using roads. There are kk types of goods produced in Byteland and every town pr

Gym .101879 USP Try-outs (寒假自训第七场)

B .Aesthetics in poetry 题意:给定N个数,(N<2000 ,a[i] <=1e9),让你找一个最大的K,使得N个数膜K的余数个数全都等于N/K个. 思路:我们找到N的因子,然后验证即可,复杂度O(N^2) #include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<=b;i++) using namespace std; const int maxn=1000010; int a[maxn],N,a

Gym -102007 :Benelux Algorithm Programming Contest (BAPC 18) (寒假自训第5场)

A .A Prize No One Can Win 题意:给定N,S,你要从N个数中选最多是数,使得任意两个之和不大于S. 思路:排序,然后贪心的选即可. #include<bits/stdc++.h> #define ll long long #define rep(i,a,b) for(int i=a;i<=b;i++) using namespace std; const int maxn=2000010; ll a[maxn]; int main() { int N,ans; l

Gym-101673 :East Central North America Regional Contest (ECNA 2017)(寒假自训第8场)

A .Abstract Art 题意:求多个多边形的面积并. 思路:模板题. #include<bits/stdc++.h> using namespace std; typedef long long ll; const double inf=1e200; const double eps=1e-12; const double pi=4*atan(1.0); int dcmp(double x){ return fabs(x)<eps?0:(x<0?-1:1);} struct

Gym102040 .Asia Dhaka Regional Contest(寒假自训第9场)

B .Counting Inversion 题意:给定L,R,求这个区间的逆序对数之和.(L,R<1e15) 思路:一看这个范围就知道是数位DP. 只是维护的东西稍微多一点,需要记录后面的各种数字的个数cnt,以及逆序对和sum,以及出现了多少种后缀num. 那么枚举到当前位时,假设为i ,那么sum+=cnt[i+1]+cnt[i+2]+....cnt[9];  cnt[i]+=num; 可以参考CF1073E. #include<bits/stdc++.h> #define rep(

Android寒假实训云笔记总结——欢迎页

欢迎页使用的是viewpager,需要适配器. 注意点: 1.判断是否是第一次进入这个app. 2.欢迎页小圆点的逻辑. 实现原理: 首先在activity_welcome放入viewpager和固定四个小圆点的图片在下方. viewpager用于存放多张欢迎页的图. welcome_selectoer用于当在哪一页对应的小圆点为灰色状态.即设置成不可点时状态为灰色. viewpager的内容为静态加载进去. 如图: 直接贴代码,代码都有注释:  WelcomeActivity.java pac

A. Nephren gives a riddle

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