CodeForces - 896A Nephren gives a riddle
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 题目链接 分析
fi由5部分拼接而成,预处理长度,因为限制了k的范围,所以只用处理到长度1e18就好。然后根据n和k递归查找所在位子的具体字符。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include <queue>
using namespace std;
typedef long long LL;
const int maxn = 1e5+;
const int mod = +;
typedef pair<int,int> pii;
#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define ms(a,b) memset(a,b,sizeof(a))
char f0[]={"What are you doing at the end of the world? Are you busy? Will you save us?"};
char t[] ={"What are you doing while sending \"\"? Are you busy? Will you send \"\"?"};
char t1[]={"What are you doing while sending \""};
char t2[]={"\"? Are you busy? Will you send \""};
char t3[]={"\"?"};
LL len[];
int l1,l2,l3,tot;
void init(){
l1=strlen(t1),l2=strlen(t2),l3=strlen(t3);
len[]=strlen(f0); int i;
for(i=;i<maxn;i++){
len[i]=+*len[i-];
if(len[i]>=1e18) break;
}
tot=i;
}
char dfs(int n,LL k){
if(n<=tot&&k>len[n]) return '.';
else{
if(n==) return f0[k-];
else{
if(k<=l1) return t1[k-];
if(n>tot || k<=l1+len[n-]) return dfs(n-,k-l1);
if(k<=l1+len[n-]+l2) return t2[k--(l1+len[n-])];
if(k<=l1+len[n-]*+l2) return dfs(n-,k-(l1+len[n-]+l2));
return t3[k--(l1+len[n-]*+l2)];
}
}
}
int main(){
// freopen("in.txt","r",stdin);
init();
int n,q;
LL k;
cin>>q;
while(q--){
cin>>n>>k;
cout<<dfs(n,k);
} return ;
}
CodeForces - 896A Nephren gives a riddle的更多相关文章
- Codeforces 897C Nephren gives a riddle:模拟【珂学】
题目链接:http://codeforces.com/contest/897/problem/C 题意: 给你一些字符串: A: [What are you doing at the end of t ...
- Codeforces Round #449 [ C/A. Nephren gives a riddle ] [ D/B. Ithea Plays With Chtholly ]
PROBLEM C/A. Nephren gives a riddle 题 http://codeforces.com/contest/896/problem/A codeforces 896a 89 ...
- CF&&CC百套计划1 Codeforces Round #449 A. Nephren gives a riddle
http://codeforces.com/contest/896/problem/A 第i个字符串嵌套第i-1个字符串 求第n个字符串的第k个字母 dfs #include<map> # ...
- Codeforces Round #449 (Div. 2)-897A.Scarborough Fair(字符替换水题) 897B.Chtholly's request(处理前一半) 897C.Nephren gives a riddle(递归)
A. Scarborough Fair time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 寒假特训——搜索——H - Nephren gives a riddle
What are you doing at the end of the world? Are you busy? Will you save us? Nephren is playing a gam ...
- A. Nephren gives a riddle
What are you doing at the end of the world? Are you busy? Will you save us? Nephren is playing a gam ...
- CF897C Nephren gives a riddle
思路: 递归. 比赛的时候脑抽了len[]没算够,wa了几次. 实现: #include <bits/stdc++.h> using namespace std; using ll = l ...
- Codeforces 897 C.Nephren gives a riddle-递归
C. Nephren gives a riddle time limit per test 2 seconds memory limit per test 256 megabytes input ...
- Codeforces Round #449 (Div. 2)ABCD
又掉分了0 0. A. Scarborough Fair time limit per test 2 seconds memory limit per test 256 megabytes input ...
随机推荐
- css3 @media 实现响应式布局
使用css3的@media,可以实现针对不同媒体.不同分辨率的响应式布局. 方法1:根据不同分辨率使用不同css文件 <link rel="stylesheet" media ...
- [转帖]以Windows服务方式运行.NET Core程序
以Windows服务方式运行.NET Core程序 原作者blog:https://www.cnblogs.com/guogangj/p/10093102.html 里面使用了NSSM 工具 但是自己 ...
- 热修改 MySQL 数据库 pt-online-schema-change 的使用详解
由于周五公司团建的关系所以此篇推迟了抱歉. 首先不得不在该篇里面梳理一个数据库热增加删除字段表的工具 pt-online-schema-change 这个工具在前面我的博文 <关于utf8mb4 ...
- rabbitmq线上服务器与项目结合的问题总结
一.特殊字符需要转义 只需要加个\反斜杠就可以了 二.zk的connectString 在rabbit web页面上登录上去,新增queue就可以了
- xhtml 意義
xhtml是html和xml的結合體. xhtml包含所有xml和html4.0結合的部分. xml是描述語言,html是顯示語言.二者結合可以產生形式良好的文檔. 不僅可以適用與電腦瀏覽器,也可以適 ...
- Java之枚举举例
package enumdemo; /** * 枚举类 */ public enum MAPPER { // 实例 ELEMENT_NAME("mapper"), ATTRIBUT ...
- 掌上电脑设备可以使用Ubuntu MATE 18.10 Linux映像了
就在几天前,Ubuntu 18.10发布了.操作系统被称为“Cosmic Cuttlefish”,有多种版本可供选择,除了常见的GNOME -- Xfce (Xbuntu), KDE (Kubuntu ...
- [代码]--c#实现屏幕取词源码下载
最近公司有一个 项目需要实现类似于金山词霸,有道词典等的屏幕取词功能,准确来说是划词功能,网上搜了各种屏幕取词无外乎就两种: A.金山词霸组件法 B.Nhw32.dll法 百度搜到的重复内容真的太多了 ...
- [IOI2018]排座位——线段树
题目链接: IOI2018seat 题目大意:给出一个$H*W$的矩阵,将$0 \sim W*H-1$分别填入矩阵的格子里(每个格子里一个数),定义一个子矩阵是美妙的当且仅当这个子矩阵包含且仅包含$0 ...
- BZOJ1367 BOI2004Sequence(左偏树)
首先考虑把bi和ai同时减i,问题变为非严格递增.显然如果a是一个递减序列,b序列所有数都取其中位数最优.于是划分原序列使得每一部分递减,然后考虑合并相邻两段.如果前一段的中位数<=后一段的中位 ...