CodeForces - 896A 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 题目链接 分析
fi由5部分拼接而成,预处理长度,因为限制了k的范围,所以只用处理到长度1e18就好。然后根据n和k递归查找所在位子的具体字符。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include <queue>
using namespace std;
typedef long long LL;
const int maxn = 1e5+;
const int mod = +;
typedef pair<int,int> pii;
#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define ms(a,b) memset(a,b,sizeof(a))
char f0[]={"What are you doing at the end of the world? Are you busy? Will you save us?"};
char t[] ={"What are you doing while sending \"\"? Are you busy? Will you send \"\"?"};
char t1[]={"What are you doing while sending \""};
char t2[]={"\"? Are you busy? Will you send \""};
char t3[]={"\"?"};
LL len[];
int l1,l2,l3,tot;
void init(){
l1=strlen(t1),l2=strlen(t2),l3=strlen(t3);
len[]=strlen(f0); int i;
for(i=;i<maxn;i++){
len[i]=+*len[i-];
if(len[i]>=1e18) break;
}
tot=i;
}
char dfs(int n,LL k){
if(n<=tot&&k>len[n]) return '.';
else{
if(n==) return f0[k-];
else{
if(k<=l1) return t1[k-];
if(n>tot || k<=l1+len[n-]) return dfs(n-,k-l1);
if(k<=l1+len[n-]+l2) return t2[k--(l1+len[n-])];
if(k<=l1+len[n-]*+l2) return dfs(n-,k-(l1+len[n-]+l2));
return t3[k--(l1+len[n-]*+l2)];
}
}
}
int main(){
// freopen("in.txt","r",stdin);
init();
int n,q;
LL k;
cin>>q;
while(q--){
cin>>n>>k;
cout<<dfs(n,k);
} return ;
}
CodeForces - 896A Nephren gives a riddle的更多相关文章
- Codeforces 897C Nephren gives a riddle:模拟【珂学】
题目链接:http://codeforces.com/contest/897/problem/C 题意: 给你一些字符串: A: [What are you doing at the end of t ...
- 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 ...
- 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 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 ...
- 寒假特训——搜索——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 ...
- CF897C Nephren gives a riddle
思路: 递归. 比赛的时候脑抽了len[]没算够,wa了几次. 实现: #include <bits/stdc++.h> using namespace std; using ll = l ...
- Codeforces 897 C.Nephren gives a riddle-递归
C. Nephren gives a riddle time limit per test 2 seconds memory limit per test 256 megabytes input ...
- Codeforces Round #449 (Div. 2)ABCD
又掉分了0 0. A. Scarborough Fair time limit per test 2 seconds memory limit per test 256 megabytes input ...
随机推荐
- HDU 1236 排名(Microsoft_zzt)
http://acm.hdu.edu.cn/showproblem.php?pid=1236 Problem Description 今天的上机考试虽然有实时的Ranklist,但上面的排名只是根据完 ...
- SMBv1 is not installed by default in Windows 10 Fall Creators Update 2017 and Windows Server, Semi-annual Channel
windows 10 rs3 release enable SMBv1 windows 10 rs3 release file sharing https://support.microsoft.co ...
- Excel 使用AutoFill提示“类Range的AutoFill方法无效”
今天遇到一个神奇的问题,之前一直使用很好的代码突然报错:“类Range的AutoFill方法无效”,在网上搜索了一番,感觉没有一个与我遇到的情况相同的.debug,查看一下代码,发现程序里,AutoF ...
- ARIMA模型识别、计算p、q值
#-*- coding: utf-8 -*- #确定最佳p.d.q值 import pandas as pd #参数初始化 discfile = '../data/discdata_processed ...
- 如何在Vue项目中引入jQuery?
假设你的项目由vue-cli初始化 (e.g. vue init webpack my-project). 在你的vue项目目录下执行: npm install jquery --save-dev 打 ...
- BZOJ5415[Noi2018]归程——kruskal重构树+倍增+堆优化dijkstra
题目描述 本题的故事发生在魔力之都,在这里我们将为你介绍一些必要的设定. 魔力之都可以抽象成一个 n 个节点.m 条边的无向连通图(节点的编号从 1 至 n).我们依次用 l,a 描述一条边的长度.海 ...
- 自学Linux Shell11.6-退出shell
点击返回 自学Linux命令行与Shell脚本之路 11.6-退出shell shell运行的每一个命令都是使用 退出状态码 告诉shell它已经运行完毕.退出状态码是一个0~255的整数值,在命令结 ...
- eclipse 代码模板
平常在借助eclipse进行开发时,有很多代码是重复的,这个时候我们可以利用eclipse自带的代码模板来进行快速输入,我们都知道,在eclipse中输入main,然后按下alt+/就会立马生成整个m ...
- happens-before
happens-before是JMM最核心的概念.对应Java程序员来说,理解happens-before是理解JMM的关键. JMM的设计 首先,让我们来看JMM的设计意图.从JMM设计者的角度,在 ...
- WEB入门之十三 jQuery选择器
学习内容 jQuery层次选择器 jQuery属性选择器 jQuery表单选择器 jQuery过滤选择器 能力目标 熟悉jQuery各种选择器的使用场合 能熟练使用jQuery各种选择器 本章简介 上 ...