zoukankan      html  css  js  c++  java
  • 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 */
  • 相关阅读:
    最新的Zynq资料整理
    异步FIFO的FPGA实现
    Mac 下安装PHP遇到的问题
    php 实现推技术comet(转)
    高性能分布式内存队列系统beanstalkd(转)
    应对Memcached缓存失效,导致高并发查询DB的四种思路(l转)
    memcache 缓存失效问题(转)
    PHP.ini文件读取不到
    PHP5中魔术方法
    python mysql 单引号字符串过滤
  • 原文地址:https://www.cnblogs.com/xingkongyihao/p/8024810.html
Copyright © 2011-2022 走看看