[Easy]CodeForces
来源:互联网 发布:淘宝网网 编辑:程序博客网 时间:2024/05/19 01:58
题目链接:
http://codeforces.com/problemset/problem/897/C
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.
Example
Input
3
1 1
1 2
1 111111111111
Output
Wh.
Input
5
0 69
1 194
1 139
0 47
1 66
Output
abdef
Input
10
4 1825
3 75
3 530
4 1829
4 1651
3 187
4 584
4 255
4 774
2 474
Output
Areyoubusy
Note
For the first two examples, refer to f0 and f1 given in the legend.
题意
- 通过题中所给递推式求出得到的第n个串的第k个字母是多少?
- 其中F(n) = s2 + F(n - 1) + s3 + F(n - 1) + s4
- s2、s3、s4以及F(0)已经给出
分析
- 由于每一个新串都是由前面的串生成的,那么就用dfs递归着往回找前面的串即可。此处要注意当n = 60的时候,生成的串长度已经大于1e18,字符串已经没办法直接存下,同时利用这一点,第k个字符一定不会出现在第一个F(n-1)之后,所以直接按出现在第二个位置的情况递归即可。
- 要注意这题好像莫名其妙会RE,把数组开大一点就过了
Code
#include <bits/stdc++.h>using namespace std;typedef unsigned long long LL;const int maxn = 2e6 + 5;LL len[maxn];string s1 = "What are you doing at the end of the world? Are you busy? Will you save us?";string s2 = "What are you doing while sending \"";string s3 = "\"? Are you busy? Will you send \"";string s4 = "\"?";void Init(){ len[0] = 75; for(int i = 1;i <= 61;i++){ len[i] = len[i - 1] * 2 + 68; }}void solve(int n,LL k){ if(n == 0) {printf("%c",s1[k - 1]);return ;} if(k <= 34) {printf("%c",s2[k - 1]); return ;} else if(k <= 34 + len[n - 1] || n > 60) solve(n - 1,k - 34); else if(k <= 66 + len[n - 1]) {printf("%c",s3[k - 35 - len[n - 1]]);return ;} else if(k <= 66 + 2 * len[n - 1]) solve(n - 1,k - 66 - len[n - 1]); else if(k == len[n]) printf("?"); else printf("\""); return ;}int main(){ Init(); int q,n; LL k; scanf("%d",&q); while(q--) { scanf("%d %lld",&n,&k); if(n <= 60) if(k > len[n]) printf("."); else solve(n,k); else solve(n,k); } printf("\n"); return 0;}
- [Easy]CodeForces
- [Easy] CodeForces
- Lucky Numbers (easy) CodeForces
- Codeforces Points and Segments (easy)
- Codeforces C1. Brain Network (easy)
- CodeForces 202B Brand New Easy Problem
- codeforces 202B Brand New Easy Problem
- Codeforces 430A Points and Segments (easy)
- Codeforces 430 A. Points and Segments (easy)
- Codeforces 430A Points and Segments (easy)
- 【CODEFORCES】 A. Appleman and Easy Task
- Codeforces 320B Ping-Pong (Easy Version)
- CodeForces - 96B Lucky Numbers (easy)
- codeforces 236 B. Easy Number Challenge
- CodeForces 320BPing-Pong (Easy Version)-DFS
- Codeforces Round #350 (Div. 2)easy
- CodeForces - 96B Lucky Numbers (easy)
- Codeforces Round #359 (Div. 2) Easy
- windows server 2012 IIS FTP 配置笔记
- utils/deb_resign.sh
- MVC介绍1
- 使用Matalab封装动态链接库(dll)供.NET(C#)调用
- 移动端jquery-pie-loader动态饼状图以及mobiscroll时间控件(最新版)
- [Easy]CodeForces
- 原生ajax和jQuery的ajax
- iOS 11 NSPhotoLibraryAddUsageDescription崩溃
- beyond compare 设置 FTP 工作在被动模式
- 论文笔记:A survey of recent advances in CNN-based single image crowd counting and density estimation
- 透明度浏览器兼容
- EdiuPlus根据ip地址连接虚拟主机
- Reactnative windows的配置
- 手上开发板盘点