递归好题啊
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 fnconsists 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 nand 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.
题意:loj那群oi大佬,就是一个人不断的重复说 有没有时间去ak之类的,找第k个字符,很明显的一个递归,代码很好理解,算出每一层语句长度,把这个语句分为三段,如果当前部分的长度比k要大,那么k-去,然后进行下一部分,否则,递归到下一层。反正答案必然在第一段,第三段,和第5段以及,f0里面。
#include <bits/stdc++.h>
using namespace std;
typedef uint64_t u64;
typedef int64_t i64;
u64 cnt[100010];
string f0="What are you doing at the end of the world? Are you busy? Will you save us?";
string fl0="What are you doing while sending \"";
string fl1="\"? Are you busy? Will you send \"";
string fl2="\"?";
char solve(u64 l,u64 s)
{
if(l==0)
{
if(s<f0.size())
return f0[s];
return '.';
}
if(s<fl0.size()){
return fl0[s];
}
s-=fl0.size();
if(s<cnt[l-1])
return solve(l-1,s);
s-=cnt[l-1];
if(s<fl1.size())
return fl1[s];
s-=fl1.size();
if(s<cnt[l-1])
return solve(l-1,s);
s-=cnt[l-1];
if(s<fl2.size())
return fl2[s];
return '.';
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
for(u64 i=1;i<=100000;i++)
cnt[i]=2ll*1000000000000000000;
cnt[0]=f0.size();
for(u64 i=1;i<=100000;i++)
{
cnt[i]=cnt[i-1]*2+fl0.size()+fl1.size()+fl2.size();
if(cnt[i]>1000000000000000000) break;
}
u64 q;
cin>>q;
stringstream ss;
for(u64 tt=0;tt<q;tt++)
{
u64 n,k;
cin>>n>>k;
ss<<solve(n,k-1);
}
cout<<ss.str()<<endl;
}