codeforces 896A dfs
来源:互联网 发布:nodejs配合什么数据库 编辑:程序博客网 时间:2024/06/06 00:18
Nephren gives a riddle
题目要求在一个无限迭代的字符串中在第n层找到第k个字母。
f(x) = sb + f(x - 1) + sc + f(x - 1) + sd
预处理出不超过范围的最大层。则下一层大于这一层的两倍。
dfs
如果在预处理层之内,且k大于该层长度,则返回 ‘.’
如果在第0层,返回原串位置
如果在sb之内,返回sb的字母
如果在f(x-1)内,递归处理;注意如果层数大于预处理的最大层,则只会在这前两个范围内。且如果要跟f()数组比较,要判断是否在预处理的层数之内
sc字符串即后面类似处理。
#include <bits/stdc++.h>using namespace std;char sa[] = "What are you doing at the end of the world? Are you busy? Will you save us?";char sb[] = "What are you doing while sending \"";char sc[] = "\"? Are you busy? Will you send \"";char sd[] = "\"?";typedef long long ll ;ll len[100] , pos , lena , lenb , lenc , lend;void init(){ lena = strlen(sa) ; lenb = strlen(sb) ; lenc = strlen(sc) ; lend = strlen(sd) ; len[0] = lena ; pos = 0 ; while(len[pos] <= 1e18){ len[++ pos] = lenb + len[pos - 1] + lenc + len[pos - 1] + lend ; }}char dfs(ll n , ll k){ if(n <= pos && k > len[n] ) return '.' ; if(n == 0) return sa[k - 1] ; if(k <= lenb) return sb[k - 1] ; k -= lenb ; if(n > pos || k <= len[n - 1]) return dfs(n - 1 , k) ; k -= len[n - 1] ; if(k <= lenc) return sc[k - 1] ; k -= lenc ; if(k <= len[n - 1]) return dfs(n - 1 , k) ; k -= len[n - 1] ; return sd[k - 1] ;}int main(){ ll op ; scanf("%lld" , &op) ; ll n , k ; init() ; while(op -- ){ scanf("%lld %lld" , &n , &k) ; printf("%c" , dfs(n , k)) ; } puts("") ; return 0 ;}
阅读全文
0 0
- codeforces 896A dfs
- Codeforces 781A dfs
- codeforces 896A Nephren gives a riddle dfs搜索
- codeforces 115A Party dfs
- dfs 遍历 codeforces 24A
- Codeforces 763A dfs+想法
- codeforces#71 A Bus Game----DFS
- codeforces 24A Ring road DFS
- Codeforces 115A- Party(DFS)
- CodeForces 264A Escape from Stones dfs
- codeforces 24A Ring road (dfs)
- CodeForces 522A(DFS||floyd最短路)
- CodeForces 24A Ring road(dfs)
- codeforces 687A - NP-Hard Problem(dfs
- codeforces 377A Maze(dfs)
- Codeforces 727A dfs打印路径
- [贪心+dfs] Codeforces 429A A. Xor-tree
- codeforces 763A Timofey and a tree(DFS)
- UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 in position 0:ordinal not in range(128)
- reading《effective c++》四
- android触摸事件的传递
- java-布局实现
- centos7环境基于jenkins、nuget、nexus的netcore持续集成
- codeforces 896A dfs
- 最大子序列和的四种不同复杂度实现
- Java运算符
- Android热更新初探,Bugly热更新的集成和使用
- 算法导论快速排序
- java 读取文件路径空格和中文的处理
- 点击登录按钮从上而下弹出登录界面窗口
- 分享一个我在面试时面对90后放的套路
- web前端第八天