寒假特训——搜索——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 ...
随机推荐
- Hibernate入门(九)级联删除
Hibernate级联删除 上一篇文章学习了级联保存和更新,这个级联删除应该很好理解的.一样的道理,删除一方,同时删除有关联的一方. https://www.cnblogs.com/deepSleep ...
- PATH环境变量
PATH是环境变量,要大写 那几个目录是你放置linux命令的目录,输入命令后系统会去PATH中寻找是否存在该命令 查看当前环境变量: echo $PATH 也可以用set命令看一下 设置: expo ...
- Java岗 面试考点精讲(基础篇02期)
1. 两个对象的hashCode相同,则equals也一定为true,对吗? 不对,答案见下面的代码: @Override public int hashCode() { return 1; } 两个 ...
- mysql不能保存中文
进入mysql文件夹,新建(修改) my.ini 文件, 修改编码 内容如下: [mysql] default-character-set=utf8
- JVM相关知识
Java虚拟机学习分享最近主要在学习JVM相关知识,-知识主要来源<深入理解JAVA虚拟机>,深有感触,结合自己的理解,整理出一些经验,由于篇幅较长,就把链接帖出来,希望对大家有所帮助: ...
- 封装个 Android 的高斯模糊组件
本篇文章已授权微信公众号 hongyangAndroid (鸿洋)独家发布 最近基于 Android StackBlur 开源库,根据自己碰到的需求场景,封装了个高斯模糊组件,顺便记录一下. 为什么要 ...
- web移动端,需要清楚设备像素比devicePixelRatio的应用
我们这里所说的devicePixelRatio其实指的是window.devicePixelRatio, 被所有WebKit浏览器以及Opera所支持. 概念 devicePixelRatio ,它是 ...
- Android 9.0新特性
1.全面屏支持,Android P加入了对刘海屏的支持,谷歌称之为凹口屏幕(display with a cutout).借助最新的提供的DisplayCutout类,开发者可以找到非功能区域的位置和 ...
- CSS回顾(基础知识,元素,选择器,盒子,颜色)
元素分类: 1.行级元素:内联元素 inline 特征:内容决定元素所占位置,不可以通过CSS改变宽高 span strong em a del 2.块级元素:block特征:独占一行,可 ...
- (其他)window10上好用的软件
1.everything:比我用电脑搜索快一些,(常用的搜索其实熟悉电脑的都会,不过想快一点) 如果你曾对效率工具有过研究,想必对 Everything 的名字不会陌生.这款仅有 1.3 MB 的小软 ...