Codeforces Round #449 div2 C(递归求解)
来源:互联网 发布:pdf.js ajax 编辑:程序博客网 时间:2024/06/09 22:11
Description
What are you doing at the end of the world? Are you busy? Will you save us?
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
input31 11 21 111111111111outputWh.input50 691 1941 1390 471 66outputabdefinput104 18253 753 5304 18294 16513 1874 5844 2554 7742 474outputAreyoubusy
题目大意
fi = “What are you doing while sending “fi - 1”? Are you busy? Will you send “fi - 1”?” 如题,根据fi的定义求fn的第k个字符是什么
解题思路
递归求解
代码实现
#include<bits/stdc++.h>using namespace std;typedef long long ll;ll len[60];int maxx,len0,len1,len2,len3;char s0[]="What are you doing at the end of the world? Are you busy? Will you save us?";char s1[]="What are you doing while sending \"";char s2[]="\"? Are you busy? Will you send \"";char s3[]="\"?";void init(){ len0=strlen(s0); len1=strlen(s1); len2=strlen(s2); len3=strlen(s3); len[0]=len0; maxx=0; while(len[maxx]<1e18+5) { maxx++; len[maxx]=len1+len[maxx-1]+len2+len[maxx-1]+len3; }}char dfs(int n,ll k){ if(n<=maxx&&k>len[n]) return '.'; if(n==0) return s0[k-1]; if(k<=len1) return s1[k-1]; k-=len1; if(n>maxx||k<=len[n-1]) return dfs(n-1,k); k-=len[n-1]; if(k<=len2) return s2[k-1]; k-=len2; if(n>maxx||k<=len[n-1]) return dfs(n-1,k); k-=len[n-1]; return s3[k-1];}int main(){ ios::sync_with_stdio(false); init(); int T,n; ll k; cin>>T; while(T--) { cin>>n>>k; cout<<dfs(n,k); } return 0;}
- Codeforces Round #449 div2 C(递归求解)
- Codeforces round 181 div2 C
- codeforces div2 round#231 C
- codeforces div2 round#230 C
- Codeforces - Round.313.Div2.C
- codeforces Round #352 div2 C
- Codeforces Round #409 div2 C
- Codeforces round#429 div2 C
- Codeforces Round #429 (Div2) C
- codeforces Round #237(div2) C解题报告
- codeforces Round #241(div2) C解题报告
- codeforces round #257 div2 C、D
- Codeforces Round #262(div2) C. Present
- codeforces Round #269(div2) C解题报告
- codeforces Round #267(div2) C解题报告
- codeforces Round #271(div2) C解题报告
- codeforces Round #272(div2) C解题报告
- codeforces Round #264(div2) C解题报告
- JDBC—JDBC中的异常处理
- Bzoj5088 HDU 6000 Wash
- 相似性度量—距离2
- 为什么要学习硬件
- Coin Change
- Codeforces Round #449 div2 C(递归求解)
- Codeforces Round #422 (Div. 2) C Hacker, pack your bags! (二分orDP)
- Object.prototype.toString.call(obj)检测对象类型?
- 日记:opencv3.0以后的版本变化
- 欢迎使用CSDN-markdown编辑器
- NVIDIA TK1 学习笔记(2):环境配置
- shadowsockets搭建
- poj1001在测试他给的数据结果一模一样,但总是wrong answer
- C++ STL 切分字符串