Codeforces Round #449 (Div. 2) C. DFS
2 seconds
256 megabytes
standard input
standard output
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?
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).
One line containing q characters. The i-th character in it should be the answer for the i-th query.
3
1 1
1 2
1 111111111111
Wh.
5
0 69
1 194
1 139
0 47
1 66
abdef
10
4 1825
3 75
3 530
4 1829
4 1651
3 187
4 584
4 255
4 774
2 474
Areyoubusy
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.
代码:
#include<bits/stdc++.h>
#define db double
#define ll long long
#define vec vector<ll>
#define Mt vector<vec>
#define ci(x) scanf("%d",&x)
#define cd(x) scanf("%lf",&x)
#define cl(x) scanf("%lld",&x)
#define pi(x) printf("%d\n",x)
#define pd(x) printf("%f\n",x)
#define pl(x) printf("%lld\n",x)
//#define rep(i, x, y) for(int i=x;i<=y;i++)
const int N = 1e6 + ;
const int mod = 1e9 + ;
const int MOD = mod - ;
const db eps = 1e-;
const db PI = acos(-1.0);
using namespace std;
string s0="What are you doing at the end of the world? Are you busy? Will you save us?",
s1="What are you doing while sending \"",s2="\"? Are you busy? Will you send \"",s3="\"?"; ll f[N]={,,,,};
int l1,l2,l3;
void init()
{
for(int i=;;i++){
ll x=f[i-]*+;
if(x>1e18) break;
f[i]=f[i-]*+;
}
}
char dfs(ll n,ll k)
{
if(!n) return k<=?s0[k-]:'.';
if(k<=l1) return s1[k-];//第一段
k-=l1;
if(k<=f[n-]||!f[n-]) return dfs(n-,k);//在范围内或者当前字符串长度远超目标位置
k-=f[n-];
if(k<=l2) return s2[k-];//s2的范围内
k-=l2;
if(k<=f[n-]||!f[n-]) return dfs(n-,k);
k-=f[n-];
return k<=l3?s3[k-]:'.';//最后一段 }
int main(){
init();
ll n,k;
int t;
ci(t);
l1=(int)s1.size(),l2=(int)s2.size(),l3=(int)s3.size();
while(t--)
{
cl(n),cl(k);
putchar(dfs(n,k));
}
return ;
}
Codeforces Round #449 (Div. 2) C. DFS的更多相关文章
- Codeforces Round #449 (Div. 2)
Codeforces Round #449 (Div. 2) https://codeforces.com/contest/897 A #include<bits/stdc++.h> us ...
- Codeforces Round #449 (Div. 2)ABCD
又掉分了0 0. A. Scarborough Fair time limit per test 2 seconds memory limit per test 256 megabytes input ...
- Codeforces Round #381 (Div. 2) D dfs序+树状数组
D. Alyona and a tree time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- Codeforces Codeforces Round #383 (Div. 2) E (DFS染色)
题目链接:http://codeforces.com/contest/742/problem/E 题意: 有一个环形的桌子,一共有n对情侣,2n个人,一共有两种菜. 现在让你输出一种方案,满足以下要求 ...
- Codeforces Round #290 (Div. 2) B (dfs)
题目链接:http://codeforces.com/problemset/problem/510/B 题意:判断图中是否有某个字母成环 思路:直接dfs就好了,注意判断条件:若下一个字母与当前字母相 ...
- Codeforces Round #222 (Div. 1) Maze —— dfs(连通块)
题目链接:http://codeforces.com/problemset/problem/377/A 题解: 有tot个空格(输入时统计),把其中k个空格变为wall,问怎么变才能使得剩下的空格依然 ...
- Codeforces Round #428 (Div. 2) C. dfs
C. Journey time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...
- Codeforces Round #321 (Div. 2) C dfs处理(双向边叶子节点的判断)
C. Kefa and Park time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- Codeforces Round #449 (Div. 2) B. Chtholly's request【偶数位回文数】
B. Chtholly's request time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
随机推荐
- hibernate课程 初探一对多映射2-2 Myeclipse进行hibernate基本配置
本节主要内容: 1 myeclipse 中hibernate jar包,mysql连接jar包 导入 2 hibernate.cfg.xml的配置 1 一对一映射已经配置过 2 hibernate.c ...
- mybatis批量插入insert时报错
报错信息: 传入的表格格式数据流(TDS)远程过程调用(RPC)协议流不正确.此 RPC 请求中提供了过多的参数.最多应为2100 错误分析: 由于mybatis拼接的sql语句参数过多导致 解决办法 ...
- 在 CentOS7 上安装 swftools
1.从官网下载 swftools,这里下载的是 0.9.2 版本: wget http://www.swftools.org/swftools-0.9.2.tar.gz 2.下载后得到 swftool ...
- PHP与redis的操作
String 类型操作 string是redis最基本的类型,而且string类型是二进制安全的.意思是redis的string可以包含任何数据.比如jpg图片或者序列化的对象 $redis-&g ...
- 表单验证插件及一些属性的用法 validate
注:必须配合jq使用. 基本语法 例如有如下: <form action="" method="post" id="demoForm" ...
- HTML5制作新年贺春
<!DOCTYPE html> <html> <head> <meta charset='UTF-8'/> <meta name='viewpor ...
- Java笔记 —— 继承
Java笔记 -- 继承 h2{ color: #4ABCDE; } a{ text-decoration: none!important; } a:hover{ color: red !import ...
- ansible使用5-Variables
变量命名 支持数字.字母.下划线 有效:foo_port, foo5 无效:foo-port, foo port, foo.port, 12 playbook定义 - hosts: webserver ...
- http 状态码集合
HTTP常见状态码 200 301 302 404 500 HTTP状态码(HTTP Status Code) 状态码并不是每个都有,为了后期扩展.[update20170505] 一些常见的状态 ...
- IOS 打开照相机 打开相册
/** * 打开照相机 */ - (void)openCamera { if (![UIImagePickerController isSourceTypeAvailable:UIImagePicke ...