CF897C Nephren gives a riddle
Posted 王宜鸣
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 }
以上是关于CF897C Nephren gives a riddle的主要内容,如果未能解决你的问题,请参考以下文章