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


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

    f0 的定义:What are you doing at the end of the world? Are you busy? Will you save us?

    f1 的定义: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?"?

    fi 的定义:What are you doing while sending "fi - 1"? Are you busy? Will you send "fi - 1"?

    bfs问题,从fi的定义中看出fi分为五个

    ABCBD:

    A:What are you doing while sending " 34个字符

    B:fi-1 75个字符

    C:"? Are you busy? Will you send " 32个字符

    D:"? 两个字符

     1 #include <bits/stdc++.h>
     2 #define ll long long
     3 #define ull unsigned long long
     4 using namespace std;
     5 const int MAX = 1e5+10;
     6 char str0[80] = {"What are you doing at the end of the world? Are you busy? Will you save us?"};
     7 char str1[80] = {"What are you doing while sending ""? Are you busy? Will you send ""?"};
     8 
     9 ull min(ull x, ull y) {
    10     return x<y?x:y;
    11 }
    12 ull cnt[MAX];
    13 char dfs(ull n, ull k) {
    14     if(k >= cnt[n]) return '.';
    15     if(n == 0) return str0[k];
    16     if(k < 34) return str1[k];
    17     k -= 34;
    18     if(k < cnt[n-1]) return dfs(n-1,k);
    19     k -= cnt[n-1];
    20     if(k < 32) return str1[34+k];
    21     k -= 32;
    22     if(k < cnt[n-1]) return dfs(n-1,k);
    23     k -= cnt[n-1];
    24     return str1[k+66];
    25 }
    26 int main(){
    27     ull q, n, k;
    28     cnt[0] = 75;
    29     for(int i=1; i<MAX; ++i) cnt[i] = cnt[i-1]*2 + 68;
    30     cin >> q;
    31     while(q--) {
    32         cin >> n >> k;
    33         printf("%c",dfs(n,k-1));
    34     }
    35     return 0;
    36 }
    37 
    38 /*
    39 What are you doing at the end of the world? Are you busy? Will you save us?
    40 
    41 What are you doing while sending "
    42 What are you doing at the end of the world? Are you busy? Will you save us?
    43 "? Are you busy? Will you send "
    44 What are you doing at the end of the world? Are you busy? Will you save us?
    45 "?
    46 
    47 What are you doing while sending "fi-1"? Are you busy? Will you send "fi-1"?
    48 */
  • 相关阅读:
    zookeeper03
    微服务网关Zuul
    微服务网关概述
    服务熔断Hystrix高级
    服务熔断Hystrix入门
    微服务架构的高并发问题
    服务注册和发现总结
    服务调用Feign高级
    服务调用Feign入门
    负载均衡Ribbon高级
  • 原文地址:https://www.cnblogs.com/xingkongyihao/p/8024810.html
Copyright © 2020-2023  润新知