博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #449 (Div. 2) C. DFS
阅读量:6265 次
发布时间:2019-06-22

本文共 3531 字,大约阅读时间需要 11 分钟。

C. Nephren gives a riddle
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard 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.

思路: 字符串长度的递推式:f[n]=2*f[n-1]+l1+l2+l3,然后分成5段来找所求字母,l1-(s[n-1])-l2-(s[n-1])-l3. 

代码:

1 #include
2 #define db double 3 #define ll long long 4 #define vec vector
5 #define Mt vector
6 #define ci(x) scanf("%d",&x) 7 #define cd(x) scanf("%lf",&x) 8 #define cl(x) scanf("%lld",&x) 9 #define pi(x) printf("%d\n",x)10 #define pd(x) printf("%f\n",x)11 #define pl(x) printf("%lld\n",x)12 //#define rep(i, x, y) for(int i=x;i<=y;i++)13 const int N = 1e6 + 5;14 const int mod = 1e9 + 7;15 const int MOD = mod - 1;16 const db eps = 1e-18;17 const db PI = acos(-1.0);18 using namespace std;19 string s0="What are you doing at the end of the world? Are you busy? Will you save us?",20 s1="What are you doing while sending \"",s2="\"? Are you busy? Will you send \"",s3="\"?";21 22 ll f[N]={
75,218,504,1076,2220};23 int l1,l2,l3;24 void init()25 {26 for(int i=5;;i++){27 ll x=f[i-1]*2+68;28 if(x>1e18) break;29 f[i]=f[i-1]*2+68;30 }31 }32 char dfs(ll n,ll k)33 {34 if(!n) return k<=75?s0[k-1]:'.';35 if(k<=l1) return s1[k-1];//第一段36 k-=l1;37 if(k<=f[n-1]||!f[n-1]) return dfs(n-1,k);//在范围内或者当前字符串长度远超目标位置38 k-=f[n-1];39 if(k<=l2) return s2[k-1];//s2的范围内40 k-=l2;41 if(k<=f[n-1]||!f[n-1]) return dfs(n-1,k);42 k-=f[n-1];43 return k<=l3?s3[k-1]:'.';//最后一段44 45 }46 int main(){47 init();48 ll n,k;49 int t;50 ci(t);51 l1=(int)s1.size(),l2=(int)s2.size(),l3=(int)s3.size();52 while(t--)53 {54 cl(n),cl(k);55 putchar(dfs(n,k));56 }57 return 0;58 }

 

转载于:https://www.cnblogs.com/mj-liylho/p/7968138.html

你可能感兴趣的文章
汇编学习(1)
查看>>
Google招聘 Lead Software Engineer
查看>>
Bzoj1026 windy数
查看>>
Java07
查看>>
mongodb基础知识_4
查看>>
ROP
查看>>
Windows常用网络命令技巧汇总 [转]
查看>>
【noi 2.6_8787】数的划分(DP){附【转】整数划分的解题方法}
查看>>
Win8 app判断网络连接状态
查看>>
CentOS 6.7下nginx SSL证书部署的方法分享
查看>>
菜鸟学SQLServer--数据文件和日志文件
查看>>
分享我积攒的测试相关的资料收集awesome-test
查看>>
1.2、solidworks入门1(零件建模、装配设计、工程图设计)
查看>>
SpringBoot Docker Mysql安装,Docker安装Mysql
查看>>
td中使用overflow:hidden; 无效解决方案
查看>>
Apache Flume 1.7.0 自定义输入输出
查看>>
第十周作业
查看>>
触摸事件基本介绍
查看>>
navigator.userAgent.indexOf来判断浏览器类型
查看>>
HDU 1556 Color the ball(树状数组)
查看>>