Codeforces Round #449 (Div. 2)C. Nephren gives a riddle

链接:http://codeforces.com/contest/897/problem/C

题意:字符串的递归。f0=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="?

      其中fi=s1+fi-1+s2+fi-1+s3;

   输入q,n,k(1<=q<=10,0 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^18);q表示询问次数,n,k,表述fn中第k个字符;当k大于fn的长度输出‘.'。

   输出fn中第k个字符。

   注意:k非常的大,可以自己测试一下当n为多少的时候长度就超过1e18,之后的字符串长度就可以与此时的fn的长度一样。

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long LL;
 4 const int maxn=1e5+5;
 5 char *f0="What are you doing at the end of the world? Are you busy? Will you save us?";
 6 ///75
 7 char *s1="What are you doing while sending \"";
 8 ///34
 9 char *s2="\"? Are you busy? Will you send \"";
10 ///31
11 char *s3="\"?";
12 ///2
13 ///fi=s1+fi-1+s2+fi-1+s3;
14 LL f[maxn];
15 char get_(LL n,LL k)
16 {
17     if(k>f[n]) return '.';
18     if(n==0) return f0[k-1];
19 
20     if(k<=strlen(s1)) return s1[k-1];///s1
21 
22     k=k-strlen(s1);
23     if(k<=f[n-1]) return get_(n-1,k);///fi-1
24 
25     k=k-f[n-1];
26     if(k<=strlen(s2)) return s2[k-1];///s2
27 
28     k=k-strlen(s2);
29     if(k<=f[n-1]) return get_(n-1,k);///fi-1
30 
31     k=k-f[n-1];
32     if(k<=strlen(s3)) return s3[k-1];///s3
33 }
34 
35 int main()
36 {
37     f[0]=75;
38     f[1]=218;
39     for(int i=2;i<=55;i++)
40         f[i]=f[i-1]*2+68;
41     for(int i=55;i<=100000;i++)
42         f[i]=f[54];///2e18
43         ///cout<<f[54];
44     LL Q,N,K;
45     char ans[maxn];
46     cin>>Q;
47     int i=0;
48     while(Q--)
49     {
50         cin>>N>>K;
51        cout<<get_(N,K);
52     }
53     return 0;
54 }
View Code

 

转载于:https://www.cnblogs.com/Y-Meng/p/7966025.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值