Codeforces#449 (Div. 2)C 字符串递归处理
来源:互联网 发布:mac删除虚拟机 编辑:程序博客网 时间:2024/06/05 15:26
题目地址:http://codeforces.com/contest/897/problem/C
C. Nephren gives a riddle
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
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
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.
【题意】:
定义一个字符串f0,然后定义字符串fi与f(i-1)的递归关系,
然后询问字符串fn的第k个字符是什么,k>长度时输出‘.’
【分析】:
由题意第一感觉,递归即可。
可是赛时脑子很渣,由于n很大,大数据爆long long 一直没处理好,每过。
之后看了别人的代码觉悟了。其实当n大于53时,k再也达不到f(n)的大小,
所以n>53时,直接让f(n)=INF即可。。。(f(n)表示长度)
【代码】:
#include<bits/stdc++.h>using namespace std;typedef long long ll;ll f[101010];char *f0="What are you doing at the end of the world? Are you busy? Will you save us?";//75char *s1="What are you doing while sending \"";//34char *s2="\"? Are you busy? Will you send \"";//32char *s3="\"?";//2char read(ll n,ll k){ if(k>f[n])return '.'; if(n==0)return f0[k-1]; if(k<=34)return s1[k-1];//1 + k-=strlen(s1); if(k<=f[n-1])return read(n-1,k); k-=f[n-1]; if(k<=strlen(s2))return s2[k-1]; k-=strlen(s2); if(k<=f[n-1])return read(n-1,k); k-=f[n-1]; if(k<=2)return s3[k-1];}int main(){ f[0]=75; f[1]=218; for(int i=2;i<=55;i++) f[i]=f[i-1]*2+68; for(int i=55;i<100010;i++) f[i]=f[53]; ll q,n,k; cin>>q; while(q--) { cin>>n>>k; printf("%c",read(n,k)); }}
- Codeforces#449 (Div. 2)C 字符串递归处理
- Codeforces Round #338 (Div. 2) C. Running Track 字符串处理
- Codeforces Round #173 (Div. 2) / 282C XOR and OR (字符串处理)
- Codeforces Round #324 (Div. 2) C. Marina and Vasya 字符串处理
- Codeforces Round #373 (Div. 2) C. Efim and Strange Grade 贪心、实数字符串"a.b"处理
- Codeforces Round #373 (Div. 2) C. Efim and Strange Grade —— 贪心 + 字符串处理
- 递归解Codeforces Round #256 (Div. 2)C. Painting Fence
- Codeforces Round #383 (Div. 2) C(递归找环求最小公倍数)
- Codeforces Round #449 (Div. 2) C. Nephren gives a riddle 递归
- Codeforces Round #256 (Div. 2/B)/Codeforces448B_Suffix Structures(字符串处理)
- Codeforces Round #313 (Div. 2) D. Equivalent Strings 字符串处理
- B. ZgukistringZ-简单字符串处理-Codeforces Round #307 (Div. 2)
- Codeforces Round #423 (Div. 2) C. String Reconstruction(字符串)
- Codeforces Round #449 (Div. 2) (B、C)
- codeforces #354(div 2) C
- codeforces #398(div.2)C
- codeforces #428 Div.2 C
- 【codeforces】Codeforces Round #370 (Div. 2) C
- cJson的用法(一) -C语言解析/生成 json数据
- CentOS 6.4 服务器版安装教程(超级详细图解)
- Spring 学习笔记(12)—— AOP 基础
- QT--项目文件的编写方法和qmake的使用
- jquery判断复选框是否选中
- Codeforces#449 (Div. 2)C 字符串递归处理
- 474. Ones and Zeroes
- 04-CSS再认识
- 深度分析CNKI知网论文查重软件的系统区别
- 常用命令
- C++编程中类class的编写(二):含指针数据的类
- HDFS精华文章汇总
- 语音增强
- fortran-时间的格式化输出