码迷,mamicode.com
首页 > 其他好文 > 详细

codeforce 896A

时间:2018-01-19 22:25:19      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:putc   else   main   出现   stl   while   blog   scanf   put   

这是一道很有意思的题。

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

#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

标签:putc   else   main   出现   stl   while   blog   scanf   put   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!