Codeforces #449 div2 C题
C. Nephren gives a riddletime 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?
InputThe 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).
OutputOne line containing q characters. The i-th character in it should be the answer for the i-th query.
ExamplesInput3
1 1
1 2
1 111111111111OutputWh.Input5
0 69
1 194
1 139
0 47
1 66OutputabdefInput10
4 1825
3 75
3 530
4 1829
4 1651
3 187
4 584
4 255
4 774
2 474OutputAreyoubusy
题目大意:fi表示第i个字符串,输入q次询问,再输入n,k;输出fn的第k个字符。如果k大于fn的长度,那么就输出'.'。
解题思路:思维题,字符串很长,不能直接dfs,只能从长度入手,判断字符在fi字符串。
因为长度倍增,所以f53的时候差不多就超过了输入的最大值,n大于53的时候在dfs特判下就行。
AC代码:
1 #include<iostream>
2 #include<bits/stdc++.h>
3 #include<stdio.h>
4 #define ll long long
5 #define MAX 1e18
6 using namespace std;
7 ll a[100500];
8 string s0,s1,s2,s3;
9 ll len1,len2,len3,len0;
10 ll most;
11 char dfs(ll n,ll k){
12 if(n==0){
13 return s0[k-1];
14 }
15 if(k<=len1){
16 return s1[k-1];
17 }
18 if(k<=len1+a[n-1]||n>most){ //特判一下
19 return dfs(n-1,k-len1);
20 }
21 if(k<=len1+a[n-1]+len2){
22 return s2[k-(len1+a[n-1])-1];
23 }
24 if(k<=len1+a[n-1]+len2+a[n-1]){
25 return dfs(n-1,k-(len1+a[n-1]+len2));
26 }
27 return s3[k-(len1+a[n-1]+len2+a[n-1])-1];
28 }
29 int main(){
30 s0="What are you doing at the end of the world? Are you busy? Will you save us?";
31 s1="What are you doing while sending \"";
32 s2="\"? Are you busy? Will you send \"";
33 s3="\"?";
34 len0=s0.length();
35 len1=s1.length();
36 len2=s2.length();
37 len3=s3.length();
38 a[0]=len0;
39 for(int i=1;i<60;i++){
40 ll s=len1+a[i-1]+len2+a[i-1]+len3;
41 if(s>MAX){
42 most=i; //most==i,如果是i-1就会RE
43 break;
44 }
45 else a[i]=s;
46 }
47 int q;
48 cin>>q;
49 while(q--){
50 ll n,k;
51 cin>>n>>k;
52 if(n<=most&&k>a[n]){
53 cout<<'.';
54 }else{
55 cout<<dfs(n,k);
56 }
57 }
58 cout<<endl;
59 return 0;
60 }
Codeforces #449 div2 C题的更多相关文章
- Codeforces #449 Div2 D
#449 Div2 D 题意 交互式类题目. 起始有 n 张纸,会给出 m 次数字 p (\(1 \leq p \leq c\)),每次可选择一张纸,并在纸上写上这个数字,如果纸上已经存在数字,会覆盖 ...
- codeforces #262 DIV2 B题 Little Dima and Equation
题目地址:http://codeforces.com/contest/460/problem/B 这题乍一看没思路.可是细致分析下会发现,s(x)是一个从1到81的数,不管x是多少.所以能够枚举1到8 ...
- codeforces 260 div2 C题
C题就是个dp,把原数据排序去重之后得到新序列,设dp[i]表示在前i个数中取得最大分数,那么: if(a[i] != a[i-1]+1) dp[i] = cnt[a[i]]*a[i] + dp[ ...
- codeforces 260 div2 B题
打表发现规律,对4取模为0的结果为4,否则为0,因此只需要判断输入的数据是不是被4整出即可,数据最大可能是100000位的整数,判断能否被4整出不能直接去判断,只需要判断最后两位(如果有)或一位能否被 ...
- Codeforces #541 (Div2) - E. String Multiplication(动态规划)
Problem Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...
- Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)
Problem Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...
- 【Codeforces #312 div2 A】Lala Land and Apple Trees
# [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...
- Codeforces #180 div2 C Parity Game
// Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...
- Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)
Problem Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...
- Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)
Problem Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...
随机推荐
- Java开发面试--Redis专区
1. 什么是Redis?它的主要特点是什么? 答: Redis是一个开源的.基于内存的高性能键值对存储系统.它主要用于缓存.数据存储和消息队列等场景. 高性能:Redis将数据存储在内存中,并采用单线 ...
- MySQL 表分区简介
MySQL表分区是一种数据库管理技术,用于将大型表拆分成更小.更可管理的分区(子表).每个分区可以独立进行维护.备份和查询,从而提高数据库性能和管理效率.以下是详细介绍MySQL表分区的步骤和注意事项 ...
- 「luogu - P4313」文理分科 Mincut
link. Pretty nice practice for the min-cut trick. Starting out we eliminate the constraint that if f ...
- FreeSWITCH容器化问题之rtp端口占用
操作系统 :CentOS 7.6_x64.debian 11 (bullseye,docker) FreeSWITCH版本 :1.10.9 Docker版本:23.0.6 FreeSWITCH容器化带 ...
- Go 基础之基本数据类型
Go 基础之基本数据类型 目录 Go 基础之基本数据类型 一.整型 1.1 平台无关整型 1.1.1 基本概念 1.1.2 分类 有符号整型(int8~int64) 无符号整型(uint8~uint6 ...
- commons中StringUtils的全解
StringUtils()方法的导入包是:org.apache.commons.lang3.StringUtils 作用是:StringUtils()方法是 Apache Commons Lang 库 ...
- CF431C
题目简化和分析: k叉树,乍一看好像是树论,但我们通过分析条件,发现它每个阶段要做的事情一样,皆为:\(1\sim k\) 中选数字,这就很明显是DP. \(\mathit{f}_{i,0}\) 表示 ...
- 【v2v迁移】Xen2kvm 迁移-Windows篇
迁移环境: 源平台:华为FusionComputeV100R006C10SPC101 目标平台:基于KVM虚拟化的云平台,本文以原生的libvirt为例 虚拟机:Windows server 2012 ...
- 聊聊RNN&LSTM
RNN 用于解决输入数据为,序列到序列(时间序列)数据,不能在传统的前馈神经网络(FNN)很好应用的问题.时间序列数据是指在不同时间点上收集到的数据,这类数据反映了某一事物.现象等随时间的变化状态或程 ...
- java 创建对象的5种方式
1.创建对象的5种方式 1.通过 new 关键字 这是最常用的一种方式,通过 new 关键字调用类的有参或无参构造方法来创建对象.比如 Object obj = new Object(); 2.通过 ...
