首页 > 其他 > 详细

codeforce 896A

时间:2018-01-19 21:51:44      阅读:231      评论:0      收藏:0      [点我收藏+]

这是一道很有意思的题。

我们递归统计其出现的位置,就好了。

#include<bits/stdc++.h>
#define LL long long
using namespace std;
char F[] = "What are you doing at the end of the world? Are you busy? Will you save us?";
char A[] = "What are you doing while sending \"";
char B[] = "\"? Are you busy? Will you send \"";
char C[] = "\"?";
const LL FL = strlen(F);
const LL AL = strlen(A);
const LL BL = strlen(B);
const LL CL = strlen(C);
const LL ALL = FL+AL+BL+CL;
int T; LL n,q;
char solve(LL a,LL b){
    if(!a) { if(b>FL) return .;else return F[(b-1)%FL];}
    if(b<=AL) return A[(b-1)%AL];
    if(a>=57) return solve(a-1,b-AL);
    LL lastL = 1;
    lastL<<=a-1; lastL*=ALL; lastL-=(AL+BL+CL); 
    if(b<=AL) return A[(b-1)%AL];
    b-=AL;
    if(b<=lastL) return solve(a-1,b);
    b-=lastL; 
    if(b<=BL) return B[(b-1)%BL];
    b-=BL;
    if(b<=lastL) return solve(a-1,b);
    b-=lastL;
    if(b<=CL) return C[(b-1)%CL];
    return .;
}
int main () {
    scanf("%d",&T);
    while (T--) {
        scanf("%lld %lld",&n,&q);
        putchar(solve(n,q));
    }
}

 

codeforce 896A

原文:https://www.cnblogs.com/rrsb/p/8318829.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!