Codeforces: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
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.

·>原题

英语奇差的我一开始并没有明白题意。看懂之后也并没有能够在训练中做出来,训练结束后立刻修改了一点小错误就过了。

首先用本人很菜的英语水平对题目意思进行翻译:奈芙莲(Nephren) 给出了一个从 f0f 无限的字符串数组 ;

其中 f0 表示{What are you doing at the end of the world? Are you busy? Will you save us?}的字符串;(大括号内的部分表示字符串,不包括大括号)

而对于 fi 定义为 {What are you doing while sending “fi-1”? Are you busy? Will you send “fi-1”?}(i>=1)

比如 f1 表示为 {What are you doing while sending “f0”? Are you busy? Will you send “f0”?}

f1 = {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?”?} (其中黑体字表示 f0 )

fi 中的字符包括字母、问号、引号和空格。

奈芙莲将询问q次,每次都会要求找寻 n = i 个的 fn 的第 k 个字符。fn 开头由1数起,如果 fn 的字符数量少于 k ,则输出 “.” (没有引号);

输入
第一行为 q (1 ≤ q ≤ 10),表示有多少个提问;
接下来 q 行输入 n 和 k (0 ≤ n ≤ 105, 1 ≤ k ≤ 1018);

输出
一行包含 q 个字符的字符串,其中第 i 个字符对应第 i 个查询;

分析:

根据题目的 fi 的递推式,除了两部分 fi-1 的之外,还有三段字符串;分别是
前段 {What are you doing while sending “};
中段 {”? Are you busy? Will you send “};
后段 {”?};

如图所示结构

fi
前段
fi-1
中段
fi-1
后段
前段
fi-2
中段
fi-2
后段
前段
fi-2
中段
fi-2
后段

很容易会想到用DFS;
通过判断 k 落在五个部分的哪个部分,如果落在 fi-1 则递归判断,如果是在其他三个部分则返回对应的字符。如果 k 超出了范围则返回 “.”;

在递归时要稍微处理一下数据。判断落在什么区间需要用到对应的 fn 的长度,因为 fn 实在是太大了,n不到100而字符串长度就已经远远超过了long long表示的64位整型的范围(n<=10000),注意到k<=1018,那超过这个长度的 fn 及其以后的 fn 可以用一个设定的无穷大(如4e18,大于k)来处理判断 k 落在对应什么部分;

即预先保存四段字符后,得到各字符串的长度后进行各 fn 长度的预处理,实际上 q 只有10组的规模下是否预处理估计差别不大;

虽然能跑,但代码写得太难看了,有很多很糟糕的地方;
仍需要继续努力。

AC代码:

#include<cstdio>
#include<cstring>
#include<queue>
#include<vector>
#include<algorithm>
#define MS(X) memset(X,0,sizeof(X))
typedef long long LL;
const LL INF=4e18;
using namespace std;
char f0[]={"What are you doing at the end of the world? Are you busy? Will you save us?"};
char ff[]={"What are you doing while sending \""};
char fm[]={"\"? Are you busy? Will you send \""};
char fb[]={"\"?"};
LL n,k,flen[100005],sn[11],sk[11];
int l0,lf,lm,lb,q;
void pre(){flen[0]=l0;for(int i=1;i<100005;i++){if(flen[i-1]>1e18) flen[i]=INF;elseflen[i]=lf+2*flen[i-1]+lm+lb;}
}char dfs(LL a,LL ft){      //这里我用ft来保存当前区间前面有多长的字符LL p=k-ft;                          if(a==0) return p<=l0?f0[p-1]:'.';  //需要判断n为0时k的情况if(p<=lf) return ff[p-1];             //前段else if(lf<p && p<=lf+flen[a-1])            //fi-1return dfs(a-1,ft+lf);else if(lf+flen[a-1]<p && p<=lf+flen[a-1]+lm) //中段return fm[p-flen[a-1]-lf-1];else if(lf+flen[a-1]+lm<p && p<=lf+2*flen[a-1]+lm)  //fi-1return dfs(a-1,ft+lf+flen[a-1]+lm);else if(lf+2*flen[a-1]+lm<p && p<=lf+2*flen[a-1]+lm+lb) //后段return fb[p-lf-2*flen[a-1]-lm-1];else return '.';                 //此处判断不包括n为0
}int main(){l0=strlen(f0);lf=strlen(ff);lm=strlen(fm);lb=strlen(fb);pre();scanf("%d",&q);for(int i=0;i<q;i++){scanf("%d%I64d",&sn[i],&sk[i]);}for(int i=0;i<q;i++){n=sn[i],k=sk[i];printf("%c",dfs(n,0));}puts("");return 0;
}

Codeforces 897C Nephren gives a riddle(DFS)相关推荐

  1. Codeforces 897C Nephren gives a riddle:模拟【珂学】

    题目链接:http://codeforces.com/contest/897/problem/C 题意: 给你一些字符串: A: [What are you doing at the end of t ...

  2. 【Codeforces 723D】Lakes in Berland (dfs)

    海洋包围的小岛,岛内的有湖,'.'代表水,'*'代表陆地,给出的n*m的地图里至少有k个湖,求填掉面积尽量少的水,使得湖的数量正好为k. dfs找出所有水联通块,判断一下是否是湖(海水区非湖).将湖按 ...

  3. Codeforces 982 C. Cut 'em all!(dfs)

    解题思路: 代码中有详细注解,以任意一点为根,dfs遍历这棵树. 每一个节点可能有好几个子树,计算每棵子树含有的节点数,再+1即为这整棵树的节点. 判断子树是否能切断与根之间的联系,如果子树含有偶数个 ...

  4. CodeForces 6D Lizards and Basements 2 (dfs)

    题意:给出一串n个元素序列.a和b,只能选择编号2 ~ n-1的s数字减a,并将相邻两数字减b,要使得所有元素为负,问至少需要多少次选择,选择是怎样的. 题解:dfs 我们可以发现只有2 ~ n-1编 ...

  5. CodeForces 6D Lizards and Basements 2(DFS)

    题意:有一串数字,每一次你可以使一个数字减少a,使相邻两个数字减少b,只能操作2-n-1次 思路:直接暴力DFS一波... #include<bits/stdc++.h> using na ...

  6. 三十二、图的创建深度优先遍历(DFS)广度优先遍历(BFS)

    一.图的基本介绍 为什么要有图 前面我们学了线性表和树 线性表局限于一个直接前驱和一个直接后继的关系 树也只能有一个直接前驱也就是父节点 当我们需要表示多对多的关系时, 这里我们就用到了图. 图的举例 ...

  7. 【 MATLAB 】离散傅里叶级数(DFS)及 IDFS 的 MATLAB 实现

    有关离散傅里叶级数(DFS)我之前也写过一些博文,例如:离散周期信号的傅里叶级数(DFS) 这里我再次给出标准公式. 分析式: 其中: 综合式: 这里我必须先声明,关于分析式和综合式前面那个系数1/N ...

  8. 部署分布式文件系统(DFS)

    部署分布式文件系统(DFS) 使用 DFS 命名空间,可以将位于不同服务器上的共享文件夹组合到一个或多个逻辑结构的命名空间.每个命名空间作为具有一系列子文件夹的单个共享文件夹显示给用户.但是,命名空间 ...

  9. Java实现算法导论中图的广度优先搜索(BFS)和深度优先搜索(DFS)

    对算法导论中图的广度优先搜索(BFS)和深度优先搜索(DFS)用Java实现其中的伪代码算法,案例也采用算法导论中的图. import java.util.ArrayList; import java ...

最新文章

  1. python安装pillow模块错误
  2. python实现复制文件功能
  3. 判断是不是链接 正则_Python 正则表达式 保姆级教程,小学生都看得懂!!
  4. Apache httpd服务
  5. [Windows]ping itsafe环境变量
  6. android 遍历对象集合,android-使用rxjava2遍历列表
  7. java comparator_Java基础之String漫谈(二)
  8. LeetCode 2. Add Two Numbers
  9. Enabled AWE
  10. 移动应用广告盈利-KeyMob移动广告聚合平台
  11. 使用 laravel Passport 做 API 认证
  12. 使用python实现日志功能
  13. 打印机服务器总是自动停止,win7系统print spooler服务总是自动停止怎么办
  14. php微信实现红包雨,怎么制作微信红包雨(微信红包雨特效)
  15. 固体物理期末3套试题
  16. ico生成工具ico制作工具ico在线制作
  17. 国美易卡借助互联网,国美易卡搭建风控、运营、营销体系
  18. 戴尔 OptiPlex 3020重新安装win10系统的教程
  19. 4个设计APP产品不得不知道的心理学原理
  20. 基于单片机心率监测的LED灯辅助睡眠系统设备-毕业设计

热门文章

  1. html在线人数统计代码,网页在线人数统计的代码
  2. 《简单的逻辑学》阅读笔记(思维导图)
  3. LCD1602显示温度符号基于Arduino
  4. 如何快速不借用转换工具将FLV格式视频转换成MP4
  5. 多款国外虚拟主机简单比较
  6. AutoCAD 快捷键
  7. 计算机快捷键里面不显示桌面,桌面显示,显示桌面快捷键不见了
  8. 深度deepin更新失败升级失败
  9. 电子与计算机工程导论,BGPLUS科研荟萃 | 杜克大学 | 电子工程、计算机工程:电子与计算机工程导论...
  10. nhieushop chovt.com hoan nghenh cac ban ghe tham nhe - chovt hovabbkb