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 ...
随机推荐
- vue打包后CSS中引用的背景图片不显示问题
vue项目中,在css样式中引用了一张背景图片,开发环境下是可以正常显示,build之后背景图片不显示. 解决方法: 找到build/utils.js文件 修改成为如下所示内容: 添加红框中的内容即 ...
- 什么是TOPO学
拓扑,一个跟门萨同样古怪的“科技Word”.其定义,对绝大多数读者而言,不一定需要理解,但无妨知道———拓扑学,数学的一门分科,研究几何图形在一对一的双方连续变换下不变的性质.不少门萨题,来自拓扑学, ...
- linux下查找字符串
如果你想在当前目录下 查找"hello,world!"字符串,可以这样: grep -rn "hello,world!" * * : 表示当前目录所有文件,也可 ...
- Android 切换主题换肤实现
思路以及实现 1.主题的切换以及实现 首先我们先来明确个概念,现在我所说的切换主题,就切换整个app的颜色风格,当然也有少部分的图片的切换.注意哦 我这边说的是少部分图片哦!如果是大面积的换图片的吧! ...
- DevExpress控件扩展之表达式编辑器
业务需求: 业务工作中经常需要对表格中的数据进行处理,包括过滤.复合计算等.过滤需要有过滤条件,复合计算需要计算公式.这两种场景都需要一个表达式编辑器.GridControl自带过滤条件的表达式编辑器 ...
- python模块介绍和 import本质
模块的定义: 用来从逻辑上组织python代码(变量,函数,类,逻辑:实现一个功能),本质上就是.py结尾的python文件. 包的定义: 用来从逻辑上组织模块的,本质上就是一个目录.(必须有一个__ ...
- 【MATLAB】对离散采样信号添加高斯白噪声(已知Eb/N0)
(1)首先计算已知信号序列(采样之后得到的信号)的平均功率.该序列在第n个点处的功率为: 如果已知的信号序列中的总共的点数为N个,则该序列的平均功率为: 在MATLAB中求平均功率的方法是: Pav= ...
- 谁动了我的I/O?
首先,是信用卡账单欠款0.13美刀~~~然后上亚马逊云查了一下账单. 3M次I/O...(1215133次超额的,2000000次免费的.) 于是监控了一下数据:每秒至少写5次,每秒写300KB,平均 ...
- python读入文档中的一行
从文件log_fusion中读入数据 方法1 f = open("log_fusion.txt") # 返回一个文件对象 line = f.readline() # 调用文件的 r ...
- Linux MySQL单实例源码编译安装5.6
cmake软件 tar -zxvf cmake-2.8.11.2.tar.gz cd cmake-2.8.11.2 ./bootstrap make make install cd ../ 依赖包 ...