codeforce 896A
这是一道很有意思的题。
我们递归统计其出现的位置,就好了。
#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)); } }