• CF897C Nephren gives a riddle


    思路:

    递归。

    比赛的时候脑抽了len[]没算够,wa了几次。

    实现:

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 using ll = long long;
     4 const string s = "What are you doing at the end of the world? Are you busy? Will you save us?";
     5 const string t = "What are you doing while sending "";
     6 const string v = ""? Are you busy? Will you send "";
     7 const ll len_s = s.length();
     8 const ll len_t = t.length();
     9 const ll len_v = v.length();
    10 ll len[100005];
    11 char dfs(ll n, ll k)
    12 {
    13     if (n == 0) 
    14     {
    15         if (k >= 1 && k <= len_s) return s[k - 1];
    16         else return '.';
    17     }
    18     else if (n >= 54)
    19     {
    20         if (k <= len_t) return t[k - 1];
    21         return dfs(n - 1, k - len_t);
    22     }
    23     else 
    24     {
    25         if (k <= len_t) return t[k - 1];
    26         else if (k > len_t && k <= len_t + len[n - 1])
    27             return dfs(n - 1, k - len_t);
    28         else if (k > len_t + len[n - 1] && k <= len_t + len[n - 1] + len_v)
    29             return v[k - len_t - len[n - 1] - 1];
    30         else if (k > len_t + len[n - 1] + len_v && k <= len_t + 2 * len[n - 1] + len_v)
    31             return dfs(n - 1, k - len_t - len[n - 1] - len_v);
    32         else if (k == len_t + 2 * len[n - 1] + len_v + 1)
    33             return '"';
    34         else if (k == len_t + 2 * len[n - 1] + len_v + 2)
    35             return '?';
    36         else return '.';
    37     }
    38 }
    39 int main()
    40 {
    41     len[0] = (ll)len_s;
    42     for (int i = 1; i <= 53; i++)
    43     {
    44         len[i] = len[i - 1] * 2 + len_t + len_v + 2;
    45     }
    46     ll q, n, k;
    47     cin >> q;
    48     while (q--)
    49     {
    50         cin >> n >> k;
    51         cout << dfs(n, k);
    52     }
    53     return 0;
    54 }
  • 相关阅读:
    单机安装nginx
    单机安装hdfs
    单机安装postgresql
    cookie和session
    zookeeper的学习笔记
    java的反射和代理
    spring boot配置404 和 500错误页面跳转
    react + ant Upload前端解析excel文件后时间解析为数字转化回日期格式
    Chrome浏览器手动添加Cookie
    实现table列拖拽插件(colResizable)
  • 原文地址:https://www.cnblogs.com/wangyiming/p/7965926.html
Copyright © 2020-2023  润新知