寒假特训——搜索——H - Nephren gives a riddle
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
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
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;
}
寒假特训——搜索——H - Nephren gives a riddle的更多相关文章
- 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> # ...
- Gym 101655:2013Pacific Northwest Regional Contest(寒假自训第13场)
A .Assignments 题意:给定距离D,以及N个飞机的速度Vi,单位时间耗油量Fi,总油量Ci.问有多少飞机可以到达目的地. 思路:即问多少飞机满足(Ci/Fi)*Vi>=D ---- ...
- Gym101986: Asia Tsukuba Regional Contest(寒假自训第12场)
A .Secret of Chocolate Poles 题意:有黑白两种木块,黑色有1,K两种长度: 白色只有1一种长度,问满足黑白黑...白黑形式,长度为L的组合种类. 思路:直接DP即可. #i ...
- 寒假特训——I - Fair
Some company is going to hold a fair in Byteland. There are nn towns in Byteland and mm two-way road ...
- Gym 101889:2017Latin American Regional Programming Contest(寒假自训第14场)
昨天00.35的CF,4点才上床,今天打的昏沉沉的,WA了无数发. 题目还是满漂亮的. 尚有几题待补. C .Complete Naebbirac's sequence 题意:给定N个数,他们在1到K ...
- Gym.102006:Syrian Collegiate Programming Contest(寒假自训第11场)
学习了“叙利亚”这个单词:比较温和的一场:几何的板子eps太小了,坑了几发. A .Hello SCPC 2018! 题意:给定一个排列,问它是否满足,前面4个是有序的,而且前面4个比后面的都小. 思 ...
- Gym.101955: Asia Shenyang Regional Contest(寒假自训第10场)
C.Insertion Sort 题意:Q次询问,每次给出N,M,Mod,问你有多少种排列,满足前面M个数字排序之后整个序列的LIS>=N-1. 思路:我们把数字看成[1,M],[N-M+1,N ...
随机推荐
- vue elementUI enter 回车 (转载)
表单提交时需要处理输入框的回车事件 一.vue原生 原生input标签可以用@keyup.enter="onSubmit" 如:<input v-on:keyup.enter ...
- [android] 采用post的方式提交数据
GET:内部实现是组拼Url的方式,http协议规定最大长度4kb,ie浏览器限制1kb POST和GET的区别比较了一下,多了几条信息 Content-Type:application/x-www- ...
- [android] listview入门
Listview组件非常重要,4分之一的时间都是在搞这个,还是通过上一节的数据库,写个for循环,插入50条数据. 先使用笨方法显示数据,根布局LinearLayout 定义一个id,在activit ...
- Java学习笔记之——Object类
所有类的祖先 如果一个类没有显式继承,则继承Object 每一个类都直接或间接的是Object的子类 相关API: protected Objectclone() 创建并返回此对象的副本. boole ...
- HDU3038(KB5-D加权并查集)
How Many Answers Are Wrong Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- git参考, 小结
git官网: https://git-scm.com 菜鸟教程: http://www.runoob.com/git/git-tutorial.html 廖雪峰: https://www.liaoxu ...
- python之把字符串形式的函数编译执行
实现效果:执行字符串形式的函数 代码如下 # name = 'aaa' # data = [18,32,33] # def hellocute(): # return "name %s ,a ...
- K8S 部署 ingress-nginx (一) 原理及搭建
Kubernetes 暴露服务的有三种方式,分别为 LoadBlancer Service.NodePort Service.Ingress.官网对 Ingress 的定义为管理对外服务到集群内服务之 ...
- 页面间固定参数,通过cookie传值
最后在做的页面,比如用户数据(用户头像,名称,年龄)这些信息,因为大部分页面都要用,之前是通过url地址传,另一页面接收.考虑到这样做会让url过长,因此,尝试使用cookie,把固定的值保存在coo ...
- mysql之全球化和本地化:字符集、校对集、中文编码问题
本文内容: 什么是字符集?什么是校对集? 查看字符集和校对集 设置字符集和校对集 mysql中的中文数据问题 首发日期:2018-04-19 什么是字符集?什么是校对集? 字符集是字母和符号的集合,每 ...