CF&&CC百套计划1 Codeforces Round #449 A. Nephren gives a riddle
http://codeforces.com/contest/896/problem/A
第i个字符串嵌套第i-1个字符串
求第n个字符串的第k个字母
dfs
#include<map>
#include<cstdio>
#include<iostream> using namespace std; typedef long long LL; char s0[]={" What are you doing at the end of the world? Are you busy? Will you save us?"};
char s1[]={" What are you doing while sending "};
char s2[]={" ? Are you busy? Will you send "};
char s3[]={" ?"}; LL f[]; void read(LL &x)
{
x=; char c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) { x=x*+c-''; c=getchar(); }
} char dfs(int x,LL y)
{
if(x<= && y>f[x]) return '.'; if(!x) return s0[y]; if(y<=) return s1[y];
y-=; if(y==) return '"';
y--; if(x>) return dfs(x-,y); if(y<=f[x-]) return dfs(x-,y);
y-=f[x-]; if(y==) return '"';
y--; if(y<=) return s2[y];
y-=; if(y==) return '"';
y--; if(y<=f[x-]) return dfs(x-,y);
y-=f[x-]; if(y==) return '"';
y--; return '?';
} int main()
{
f[]=;
for(int i=;i<;++i) f[i]=+f[i-]*;
int q;
scanf("%d",&q);
int n; LL k;
while(q--)
{
scanf("%d",&n);
read(k);
printf("%c",dfs(n,k));
}
}
2 seconds
256 megabytes
standard input
standard output
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?
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).
One line containing q characters. The i-th character in it should be the answer for the i-th query.
3
1 1
1 2
1 111111111111
Wh.
5
0 69
1 194
1 139
0 47
1 66
abdef
10
4 1825
3 75
3 530
4 1829
4 1651
3 187
4 584
4 255
4 774
2 474
Areyoubusy
For the first two examples, refer to f0 and f1 given in the legend.
CF&&CC百套计划1 Codeforces Round #449 A. Nephren gives a riddle的更多相关文章
- CF&&CC百套计划1 Codeforces Round #449 C. Willem, Chtholly and Seniorious (Old Driver Tree)
http://codeforces.com/problemset/problem/896/C 题意: 对于一个随机序列,执行以下操作: 区间赋值 区间加 区间求第k小 区间求k次幂的和 对于随机序列, ...
- CF&&CC百套计划1 Codeforces Round #449 B. Ithea Plays With Chtholly
http://codeforces.com/contest/896/problem/B 题意: 交互题 n张卡片填m个1到c之间的数,1<=n*ceil(c/2)<=m 最后填出一个单调非 ...
- CF&&CC百套计划4 Codeforces Round #276 (Div. 1) A. Bits
http://codeforces.com/contest/484/problem/A 题意: 询问[a,b]中二进制位1最多且最小的数 贪心,假设开始每一位都是1 从高位i开始枚举, 如果当前数&g ...
- CF&&CC百套计划4 Codeforces Round #276 (Div. 1) E. Sign on Fence
http://codeforces.com/contest/484/problem/E 题意: 给出n个数,查询最大的在区间[l,r]内,长为w的子区间的最小值 第i棵线段树表示>=i的数 维护 ...
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) A. Jeff and Rounding
http://codeforces.com/problemset/problem/351/A 题意: 2*n个数,选n个数上取整,n个数下取整 最小化 abs(取整之后数的和-原来数的和) 先使所有的 ...
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) D. Jeff and Removing Periods
http://codeforces.com/problemset/problem/351/D 题意: n个数的一个序列,m个操作 给出操作区间[l,r], 首先可以删除下标为等差数列且数值相等的一些数 ...
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) E. Jeff and Permutation
http://codeforces.com/contest/351/problem/E 题意: 给出一些数,可以改变任意数的正负,使序列的逆序对数量最少 因为可以任意加负号,所以可以先把所有数看作正数 ...
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) B. Jeff and Furik
http://codeforces.com/contest/351/problem/B 题意: 给出一个n的排列 第一个人任选两个相邻数交换位置 第二个人有一半的概率交换相邻的第一个数>第二个数 ...
- CF&&CC百套计划2 CodeChef December Challenge 2017 Chef And Easy Xor Queries
https://www.codechef.com/DEC17/problems/CHEFEXQ 题意: 位置i的数改为k 询问区间[1,i]内有多少个前缀的异或和为k 分块 sum[i][j] 表示第 ...
随机推荐
- 软工网络15团队作业8——Beta阶段敏捷冲刺(Day5)
提供当天站立式会议照片一张 每个人的工作 1.讨论项目每个成员的昨天进展 赵铭: 进一步数据整理,写入数据库. 吴慧婷:主页面.查单词页面的改进.背单词界面改进. 陈敏: 单词学习功能及该界面按钮功能 ...
- Git命令提交项目代码
Git客户端安装 今天就结合`GitHub`,通过`Git`命令,来了解如何实现开源代码库以及版本控制 GitHub是一个面向开源及私有软件项目的托管平台,因为只支持Git 作为唯一的版本库格式进行托 ...
- linux 搭建epel本地库,并定时同步
1.安装rsyncyum -y install rsync.x86_64 2.同步epel至本地#http://mirrors.ustc.edu.cn/status/ 获取镜像库rsync路径mkdi ...
- Idea(二) 解决IDEA卡顿问题及相关基本配置
一.IDEA太卡顿,设置使用IDEA的内存 在IDEA的安装目录下的bin目录下: 打开设置: 将idea.exe.vmoptions文件内由-server-Xms128m-Xmx512m-XX:Ma ...
- CSS实现点击改变元素背景色
可通过使用css伪类实现点击元素变色的效果,两个伪类是:active, :focus :active :active选择器用于选择活动链接.当在一个链接上点击时,它就会成为活动的(激活的),:acti ...
- matlab中 assert(any(mask(:)));
首先,matlab中any函数:检测矩阵mask中是否有非零元素,如果有,返回1,:如果没有非零元素,即所有元素都是0,那么则返回0. assert()是一个调试程序时经常使用的宏,在程序运行时它计算 ...
- Python 的 “Magic” 方法
在以前的文章中,我聊过了Python的 __getitem__ 和 __setitem__ 方法.这些方法被称为“魔法”方法.特殊方法或者dunger方法(译者:国内书籍用“魔法”一词较多).那么,什 ...
- BZOJ5099 POI2018Pionek
假设确定了最终所得向量的方向,则应该选择所有在该方向上投影为正的向量.按极角序排序后这显然是一段连续区间.最终向量方向很难枚举,但对于某个向量,在其上投影为正的向量与其夹角范围是(-π/2,π/2), ...
- P1198 [JSOI2008]最大数
题目描述 现在请求你维护一个数列,要求提供以下两种操作: 1. 查询操作. 语法:Q L 功能:查询当前数列中末尾L个数中的最大的数,并输出这个数的值. 限制:L不超过当前数列的长度.(L>0) ...
- git gitosis 添加项目
example: 1, user@my-test:~/perl_src$ git inituser@my-test:~/perl_src$ git add .user@my-test:~/perl_s ...