Codeforces#449 (Div. 2)C 字符串递归处理
2017-12-03 11:04
399 查看
题目地址: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)表示长度)
【代码】:
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?"; //75 char *s1="What are you doing while sending \""; //34 char *s2="\"? Are you busy? Will you send \""; //32 char *s3="\"?"; //2 char read(ll n,ll k) { if(k>f )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 Round #313 (Div. 2) D. Equivalent Strings(字符串+递归)
- Codeforces Round #375 (Div. 2) B. Text Document Analysis(字符串处理,简单题目)
- 字符串处理 Codeforces Round #297 (Div. 2) B. Pasha and String
- 字符串处理 Codeforces Round #285 (Div. 2) B. Misha and Changing Handles
- Codeforces Round #254 (Div. 2)445A DZY Loves Chessboard(字符串处理)
- Codeforces Round #329 (Div. 2)A 字符串处理
- Codeforces Round #163 (Div. 2) / 226A Stones on the Table (字符串处理)
- Codeforces Round #373 (Div. 2) C. Efim and Strange Grade —— 贪心 + 字符串处理
- 字符串处理 Codeforces Round #296 (Div. 2) B. Error Correct System
- 字符串处理/贪心 Codeforces Round #307 (Div. 2) B. ZgukistringZ
- Codeforces Beta Round #70 (Div. 2) / 78A Haiku (字符串处理)
- Codeforces Round #256 (Div. 2/B)/Codeforces448B_Suffix Structures(字符串处理)
- Codeforces Round #401 (Div. 2) D. Cloud of Hashtags 贪心、字符串处理
- hihoCoder - hiho字符串2 ---字符串的递归处理
- 递归处理字符串中字符出现次数并按出现顺序返回
- Codeforces Round #389 (Div. 2) B. Santa Claus 贪心+字符串处理、易错
- Codeforces Round #373 (Div. 2) C. Efim and Strange Grade 贪心、实数字符串"a.b"处理
- Codeforces Round #208 (Div. 2) Problem B Dima and Text Messages(简单字符串处理)
- Codeforces Round #424 (Div. 2) B. Keyboard Layouts(字符串处理)
- Codeforces Round #186 (Div. 2) / 313B Ilya and Queries (字符串处理)