A. 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?
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.
长度预处理+递归
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 2147483647
const ll INF = 0x3f3f3f3f3f3f3f3fll;
#define ri register int
template <class T> inline T min(T a, T b, T c)
{
return min(min(a, b), c);
}
template <class T> inline T max(T a, T b, T c)
{
return max(max(a, b), c);
}
template <class T> inline T min(T a, T b, T c, T d)
{
return min(min(a, b), min(c, d));
}
template <class T> inline T max(T a, T b, T c, T d)
{
return max(max(a, b), max(c, d));
}
#define scanf1(x) scanf("%d", &x)
#define scanf2(x, y) scanf("%d%d", &x, &y)
#define scanf3(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define scanf4(x, y, z, X) scanf("%d%d%d%d", &x, &y, &z, &X)
#define pi acos(-1)
#define me(x, y) memset(x, y, sizeof(x));
#define For(i, a, b) for (int i = a; i <= b; i++)
#define FFor(i, a, b) for (int i = a; i >= b; i--)
#define bug printf("***********\n");
#define mp make_pair
#define pb push_back
const int N = ;
// name*******************************
ll len1,len2,len3;
ll f[N];
string s0="What are you doing at the end of the world? Are you busy? Will you save us?";
string s1="What are you doing while sending \"";
string s2="\"? Are you busy? Will you send \"";
string s3="\"?";
int q,n;
// function******************************
void init()
{
f[]=s0.size();
len1=s1.size();
len2=s2.size();
len3=s3.size();
For(i,,N)
{
if(f[i-]>=INF)
{
f[i]=INF;
continue;
}
f[i]=len1+f[i-]+len2+f[i-]+len3;
}
} void solve(ll n,ll k)
{
if(n==)
{
printf("%c",s0[k-]);
return;
}
if(k<=len1)
{
printf("%c",s1[k-]);
}
else if(k<=len1+f[n-])
{
solve(n-,k-len1);
}
else if(k<=len1+f[n-]+len2)
{
printf("%c",s2[k-len1-f[n-]-]);
}
else if(k<=len1+f[n-]+len2+f[n-])
{
solve(n-,k-len1-f[n-]-len2);
}
else
{
printf("%c",s3[k-len1-f[n-]-len2-f[n-]-]);
}
} //***************************************
int main()
{
// ios::sync_with_stdio(0);
// cin.tie(0);
// freopen("test.txt", "r", stdin);
// freopen("outout.txt","w",stdout);
scanf("%d",&q);
init();
while(q--)
{
ll a,b;
scanf("%lld%lld",&a,&b);
if(f[a]<b)
{
printf(".");
continue;
}
solve(a,b);
} return ;
}
A. Nephren gives a riddle的更多相关文章
- 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 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 ... 
- 寒假特训——搜索——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 ... 
- 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 897C Nephren gives a riddle:模拟【珂学】
		题目链接:http://codeforces.com/contest/897/problem/C 题意: 给你一些字符串: A: [What are you doing at the end of t ... 
- 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 ... 
随机推荐
- openstack-on-centos7之环境准备
			centos7配置静态ip ifconfig查看网卡信息并获取到网卡的名称eth0s3 ifconfig 进入到网卡配置目录 cd /etc/sysconfig/network-scripts/ 找到 ... 
- promise的理解和应用
			老铁们,我又满血复活了,今天我准备来吹一波我对promise,如有错吴请直接指出,明白了吗?话不多说开始吧 首先我们需要知道啥叫promise,我问了问大佬,他说这个东西是 异步操作的同步代码(but ... 
- 【代码笔记】iOS-导航条的标题(label)
			一,效果图. 二,代码. - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the ... 
- 【代码笔记】iOS-Label随字自动变大
			一,效果图. 二,工程图. 三, 代码. RootViewController.h #import <UIKit/UIKit.h> //添加HPGrowingTextView头文件 #im ... 
- [基础架构]PeopleSoft Web Server 重要文件说明
			我们都知道PeopleSoft是由几个不同的服务组成的,他们在PeopleSoft体系结构中扮演着自己的角色.这些服务具有不同的文件结构并包含重要的可执行文件和配置文件. 以下是Peoplesoft体 ... 
- CAT3 SAP tcode - Time Sheet: Display Times
			CAT3 SAP tcode - Time Sheet: Display Times CAT3 (Time Sheet: Display Times) is a standard SAP transa ... 
- Hbase到Solr数据同步及Solr分离实战
			1. 起因 由于历史原因,公司的数据是持久化在HBase中,查询是通过Solr来实现,这这样的设计必然涉及到要把Hbase中的数据实时同步到Solr,但所有的服务都在一个同一个集群及每台机子都安装了很 ... 
- js替换数组中字符串实例
			这个是替换数组中的一个对象字符串: 直接上代码: var aaa=[ {"name":"张珊","sex":"man"} ... 
- 本地用maven搭建SpringMvc+redis集成
			---恢复内容开始--- 首先本地需要搭建私服,简单说一下搭建私服的步骤 1.为什么使用Nexus 如果没有私服,我们所需的所有构件都需要通过maven的中央仓库和第三方的Maven仓库下载到本地,而 ... 
- webpack+sass+vue 入门教程(一)
			一.安装node.js node.js是基础,必须先安装.而且最新版的node.js,已经集成了npm. 下载地址 node安装,一路按默认即可. 二.全局安装webpack npm install ... 
