Codeforces 897 C.Nephren gives a riddle-递归
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.
题意看了好久,才明白什么意思。
除了f0 ,其他的都是在固定的那两句话和问号中插入上一个f的内容。就是假设a b c ,在a和b中间和b和c中间插入上一个f的内容。
这个题先处理一下1e5的数据的长度。首先先初始化,初始化的数组存的长度只要大于1e5就可以,因为题目说f的长度大于1e5就输出.(输出点.)
为什么一定要初始化呢,假设是第53个f的长度大于1e5,53之后的f的长度都应该是大于1e5的,但是处理的时候53以后的已经跳出了。
所以在一开始赋初值的的时候就先把长度赋值大于1e5就可以。
我写的1e5+1,哈哈哈。
然后就是递归处理,依次判断然后减去就可以。
对于问号的处理可以先递归模拟一下前几个f就可以。
其他的没什么坑了。
直接代码:
1 //C.Sorting Railway Cars 递归
2 #include<iostream>
3 #include<cstring>
4 #include<cstdio>
5 #include<cmath>
6 #include<algorithm>
7 using namespace std;
8 typedef long long ll;
9 const int N=1e5+10;
10 char a0[]={"What are you doing at the end of the world? Are you busy? Will you save us?"};
11 char a1[]={"What are you doing while sending \""};
12 char a2[]={"\"? Are you busy? Will you send \""};
13 char a3[]={"\"?"};
14 ll len[N];
15 ll l0,l1,l2,l3;
16 char digui(ll n,ll k){
17 if(n==0)return a0[k-1];
18 if(k<=l1)return a1[k-1];k-=l1;
19 if(k<=len[n-1])return digui(n-1,k);k-=len[n-1];
20 if(k<=l2)return a2[k-1];k-=l2;
21 if(k<=len[n-1])return digui(n-1,k);k-=len[n-1];
22 return a3[k-1];
23 }
24 int main(){
25 l0=strlen(a0);
26 l1=strlen(a1);
27 l2=strlen(a2);
28 l3=strlen(a3);
29 len[0]=l0;
30 for(ll i=1;i<=1e5;i++)
31 len[i]=1e18+1;
32 for(int i=1;i<=1e5;i++){
33 len[i]=len[i-1]*2+l1+l2+l3;
34 if(len[i]>1e18)break;
35 }
36 char ans[N];
37 ll q,n,k;
38 while(~scanf("%lld",&q)){
39 memset(ans,0,sizeof(ans));
40 ll h=0;
41 while(q--){
42 scanf("%lld%lld",&n,&k);
43 if(k>len[n])ans[h++]='.';
44 else ans[h++]=digui(n,k);
45 }
46 for(int i=0;i<h;i++)
47 cout<<ans[i];
48 }
49 return 0;
50 }
cf的测评姬小姐姐最近可能心情不好,打cf的时候测题好慢。
加油啊,简直要菜哭了。
咸鱼加油,好好对待我的id,ZERO。
向学长学习ZEROm。
Codeforces 897 C.Nephren gives a riddle-递归的更多相关文章
- Codeforces Round #449 (Div. 2)-897A.Scarborough Fair(字符替换水题) 897B.Chtholly's request(处理前一半) 897C.Nephren gives a riddle(递归)
A. Scarborough Fair time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #449 [ C/A. Nephren gives a riddle ] [ D/B. Ithea Plays With Chtholly ]
PROBLEM C/A. Nephren gives a riddle 题 http://codeforces.com/contest/896/problem/A codeforces 896a 89 ...
- CodeForces - 896A Nephren gives a riddle
A. Nephren gives a riddle time limit per test 2 seconds memory limit per test 256 megabytes input st ...
- 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> # ...
- Codeforces 897C Nephren gives a riddle:模拟【珂学】
题目链接:http://codeforces.com/contest/897/problem/C 题意: 给你一些字符串: A: [What are you doing at the end of t ...
- 寒假特训——搜索——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 gam ...
- 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 gam ...
- CodeForces - 896D :Nephren Runs a Cinema(卡特兰数&组合数学---比较综合的一道题)
Lakhesh loves to make movies, so Nephren helps her run a cinema. We may call it No. 68 Cinema. Howev ...
- Codeforces 897 B.Chtholly's request-思维题(处理前一半)
B. Chtholly's request time limit per test 2 seconds memory limit per test 256 megabytes input st ...
随机推荐
- Problem E. TeaTree - HDU - 6430 (树的启发式合并)
题意 有一棵树,每个节点有一个权值. 任何两个不同的节点都会把他们权值的\(gcd\)告诉他们的\(LCA\)节点.问每个节点被告诉的最大的数. 题解 第一次接触到树的启发式合并. 用一个set维护每 ...
- 二叉树的镜像(Python实现)
题目 给定一棵二叉树,要求输出其左右翻转后二叉树的中序遍历. 例: 翻转前: 翻转后: 1 | 1 / \ | / \ 2 3 | 3 2 / \ | / \ 4 5 | 5 4 解析 两个步骤: 镜 ...
- leetcode 【 Search in Rotated Sorted Array 】python 实现
题目: Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 ...
- ogre3D学习基础3 -- 粒子与表层脚本
9.粒子脚本 粒子脚本允许你实例化地在你的脚本代码中定义粒子系统,而不必在源代码中进行设置,使得你做任何修改都能得到快速回应.脚本里定义的粒子系统被用作模板,并且多个实际的系统可以在运行时从这里被创建 ...
- log4j2用asyncRoot配置异步日志是如何使用disruptor
用asyncRoot配置对应的对接disruptor类是AsyncLoggerConfigDisruptor,用Log4jContextSelector启动参数配置全局异步的对应的对接disrupto ...
- Django-缓存机制、跨域请求(CORS)、ContentType组件
Django缓存机制: 在settings中间件里面设置: 三个粒度: 1 全站缓存 用中间件: MIDDLEWARE = [ # 'django.middleware.cache.UpdateCac ...
- [python][django学习篇][8]django 视图(2) --简单模板
在视图函数里返回的是一个 HttpResponse 类的实例,我们给它传入了一个希望显示在用户浏览器上的字符串.但是我们的博客不可能只显示这么一句话,它有可能会显示很长很长的内容.比如我们发布的博客文 ...
- 翻译MDN里js的一些方法属性
TypeError The TypeError object represents an error when a value is not of the expected type. [TypeEr ...
- 声卡(Sound Card)基本概念
声卡 (Sound Card)是实现声音的模拟/数字信号相互转换.信号处理的一种硬件. 声卡的基本功能是把来自话筒.磁带.光盘的原始声音信号加以转换(模数转换或者数模转换),输出到耳机.扬声器.扩音机 ...
- C#中的is和as的转型区别
摘自CLR via C#第三版第四章 在c#中is可以用来判断一个对象是否兼容给定的类型,如果是返回true,否则返回false. 同时is是永不会抛出异常的.如果对象引用是null,is操作符总是返 ...