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] 表示第 ...
随机推荐
- oh my god 四则运算
Week1地址:https://git.coding.net/leiqh549/four.git 需求分析: 1.一个生成n道四则运算的程序,要求数字在0-100间,运算符在3-5个之间且运算符至少包 ...
- 12_Java面向对象_第12天(构造方法、this、super)_讲义
今日内容介绍 1.构造方法 2.this关键字 3.super关键字 4.综合案例 01构造方法引入 A:构造方法的引入 在开发中经常需要在创建对象的同时明确对象的属性值, 比如员工入职公司就要明确他 ...
- C++操作mysql方法总结(2)
C++通过ODBC和通过MFC ODBC操作mysql的两种方式 使用vs2013和64位的msql 5.6.16进行操作 项目中使用的数据库名和表数据请参考C++操作mysql方法总结(1)中的介绍 ...
- 初识nginx——配置解析篇
一.nginx的介绍 nginx是由俄罗斯人开发的一款高性能的http和反向代理服务器,也可以用来作为邮件代理.相比较于其他的服务器,具有占用内存少,稳定性高等优势 二.nginx的配置 nginx的 ...
- 11git更改提交
.将不必要的文件add .上次提交觉得是错的 .不想改变暂存区内容,只是想调整提交的信息 .版本回滚 git reset HEAD 文件名 移除不必要的添加到暂存区的文件 git reset HEAD ...
- Ubuntu下面 PHPSTORM2017.2破解方法
Ubuntu下面 PHPSTORM2017.2破解方法 下载破解文件 在 http://idea.lanyus.com/上面新下载一个破解文件. 破解步骤 将JetbrainsCrack-2.6.3_ ...
- equals比较对象
object类的equals方法用来比较是否是同一个对象,比较内存地址. jdk中有些类重写了equals方法,只要类型,内容相同,就相等. 类如果涉及到比较应该重写equals方法,比较内存地址没有 ...
- TFS(Team Foundation Server) 权限设置记录
环境: TFS2012 + win7 1.安装好TFS 2.创建系统用户组: TFSAdmins.TFSDevs.TFSUsers 分别为TFS管理人员组.TFS开发人员组.TFS普通用户组. 如下图 ...
- shell的sed命令
sed命令用于在线编辑文本,它一次处理一行内容. 命令语法: sed [-n/e/f/r/i] [cmd] [InFile] 参数解释: 选项与参数: -n: quiet/silent,安静模式,经过 ...
- VDOM configuration
VDOM configuration 来源 https://cookbook.fortinet.com/vdom-configuration/ Posted on January 6, 2015 by ...