zoukankan      html  css  js  c++  java
  • Codeforces Round #449 (Div. 2) C. DFS

    C. Nephren gives a riddle
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard 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?

    Input

    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).

    Output

    One line containing q characters. The i-th character in it should be the answer for the i-th query.

    Examples
    input
    3
    1 1
    1 2
    1 111111111111
    output
    Wh.
    input
    5
    0 69
    1 194
    1 139
    0 47
    1 66
    output
    abdef
    input
    10
    4 1825
    3 75
    3 530
    4 1829
    4 1651
    3 187
    4 584
    4 255
    4 774
    2 474
    output
    Areyoubusy
    Note

    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. 

    代码:

     1 #include<bits/stdc++.h>
     2 #define db double
     3 #define ll long long
     4 #define vec vector<ll>
     5 #define Mt  vector<vec>
     6 #define ci(x) scanf("%d",&x)
     7 #define cd(x) scanf("%lf",&x)
     8 #define cl(x) scanf("%lld",&x)
     9 #define pi(x) printf("%d
    ",x)
    10 #define pd(x) printf("%f
    ",x)
    11 #define pl(x) printf("%lld
    ",x)
    12 //#define rep(i, x, y) for(int i=x;i<=y;i++)
    13 const int N   = 1e6 + 5;
    14 const int mod = 1e9 + 7;
    15 const int MOD = mod - 1;
    16 const db  eps = 1e-18;
    17 const db  PI  = acos(-1.0);
    18 using namespace std;
    19 string s0="What are you doing at the end of the world? Are you busy? Will you save us?",
    20 s1="What are you doing while sending "",s2=""? Are you busy? Will you send "",s3=""?";
    21 
    22 ll f[N]={75,218,504,1076,2220};
    23 int l1,l2,l3;
    24 void init()
    25 {
    26     for(int i=5;;i++){
    27         ll x=f[i-1]*2+68;
    28         if(x>1e18) break;
    29         f[i]=f[i-1]*2+68;
    30     }
    31 }
    32 char dfs(ll n,ll k)
    33 {
    34     if(!n) return k<=75?s0[k-1]:'.';
    35     if(k<=l1) return s1[k-1];//第一段
    36     k-=l1;
    37     if(k<=f[n-1]||!f[n-1]) return dfs(n-1,k);//在范围内或者当前字符串长度远超目标位置
    38     k-=f[n-1];
    39     if(k<=l2) return s2[k-1];//s2的范围内
    40     k-=l2;
    41     if(k<=f[n-1]||!f[n-1]) return dfs(n-1,k);
    42     k-=f[n-1];
    43     return k<=l3?s3[k-1]:'.';//最后一段
    44 
    45 }
    46 int main(){
    47     init();
    48     ll n,k;
    49     int t;
    50     ci(t);
    51     l1=(int)s1.size(),l2=(int)s2.size(),l3=(int)s3.size();
    52     while(t--)
    53     {
    54         cl(n),cl(k);
    55         putchar(dfs(n,k));
    56     }
    57     return 0;
    58 }
  • 相关阅读:
    使用eNSP配置灵活QinQ
    使用eNSP配置端口QinQ
    python-多线程编程
    front-end plugin, generate pdf with html5 and jquery
    dotnetnuke peek. glance.
    a
    租房了,说一个奇妙的事情。
    总是容易忘记zen coding里怎么写标签text, mark一下吧
    springboot+druid连接池及监控配置
    springboot +mybatis分页插件PageHelper
  • 原文地址:https://www.cnblogs.com/mj-liylho/p/7968138.html
Copyright © 2011-2022 走看看