Soft kittytime limit:1000msmemory limit:65536kb64-bit integer IO format:%lld Java class name: Main Prev Submit Status Statistics discuss Next
Laimao very much like this "BigBang" in the "Soft Kitty", the song lyrics is simple only 6 words, "Soft kitty, warm Kitty, little ball of Fur,happy Kitty, sleepy Kitty, Pu RR purr Purr. "She was always singing and playing. Now she's bored. Decided to change a play, you say a number n, she sings the nth (1≤n≤10^9) sentence lyrics. Attention to her singing is, the first time I sing this song, each word repeats 2^ (i-1) times. Just like this, "soft kitty, warm kitty, little ball of fur, happy Kitty, sleepy kitty, purr purr purr, soft kitty, soft kitty, warm Kitty, warm Kitty, little ball of the fur, little ball of fur,...... "can you help her output the nth verse (not including punctuation)?
Input
Multiple sets of data, the first line is an integer K (0<k<=100), which represents the number of data groups. The next K-line, a number n per line, indicates that you need to output the nth verse.
Output
Output corresponding lyrics
Sample Input
812345678
Sample Output
Soft kittywarm kittylittle Ball of Furhappy kittysleepy Kittypurr purr Purrsoft kittysoft kitty
Error point analysis: prefix and calculation error, data range is not considered good, to use the Longlong int
The idea of solving problems: using prefixes and subscripts to map n songs.
#include <stdio.h> #include <string.h> #include <string># include<iostream> #include <math.h> #include <algorithm>using namespace Std;long long F[50];long long Suf[50];string ss[10];void work () {ss[0]= "soft kitty"; ss[1]= "Warm Kitty"; Ss[2]= "Little Ball of fur"; ss[3]= "Happy Kitty"; Ss[4]= "Sleepy Kitty"; ss[5]= "Purr purr purr"; f[0]=0; suf[0]=0; f[1]=6; suf[1]=6; for (int i=2;i<50;i++) {f[i]=f[i-1]*2; Suf[i]=suf[i-1]+f[i]; }}void solve (Long long m) {int i; for (i=1;i<50;i++) {if (suf[i]>=m) {break; }} M-=suf[i-1]; Long ti= (Long Long) POW (2,i-1); if (m%ti==0) {cout<<ss[m/ti-1]<<endl; }else{cout<<ss[m/ti]<<endl; }}int Main () {int K; Work (); scanf ("%d", &k); while (k--) {long long n; scanf ("%lld", &n); Solve (n); } return 0;}
Bnu27937--soft Kitty —————— "extended prefixes and"