Soft Kitty
Time Limit: 1000ms
Memory Limit: 65536KB
64-bit integer IO format: %lld Java class name: Main
Submit Status Statistics Discuss
Type:
None
Graph Theory
2-SAT
Articulation/Bridge/Biconnected Component
Cycles/Topological Sorting/Strongly Connected Component
Shortest Path
Bellman Ford
Dijkstra/Floyd Warshall
Euler Trail/Circuit
Heavy-Light Decomposition
Minimum Spanning Tree
Stable Marriage Problem
Trees
Directed Minimum Spanning Tree
Flow/Matching
Graph Matching
Bipartite Matching
Hopcroft–Karp Bipartite Matching
Weighted Bipartite Matching/Hungarian Algorithm
Flow
Max Flow/Min Cut
Min Cost Max Flow
DFS-like
Backtracking with Pruning/Branch and Bound
Basic Recursion
IDA* Search
Parsing/Grammar
Breadth First Search/Depth First Search
Advanced Search Techniques
Binary Search/Bisection
Ternary Search
Geometry
Basic Geometry
Computational Geometry
Convex Hull
Pick‘s Theorem
Game Theory
Green Hackenbush/Colon Principle/Fusion Principle
Nim
Sprague-Grundy Number
Matrix
Gaussian Elimination
Matrix Exponentiation
Data Structures
Basic Data Structures
Binary Indexed Tree
Binary Search Tree
Hashing
Orthogonal Range Search
Range Minimum Query/Lowest Common Ancestor
Segment Tree/Interval Tree
Trie Tree
Sorting
Disjoint Set
String
Aho Corasick
Knuth-Morris-Pratt
Suffix Array/Suffix Tree
Math
Basic Math
Big Integer Arithmetic
Number Theory
Chinese Remainder Theorem
Extended Euclid
Inclusion/Exclusion
Modular Arithmetic
Combinatorics
Group Theory/Burnside‘s lemma
Counting
Probability/Expected Value
Others
Tricky
Hardest
Unusual
Brute Force
Implementation
Constructive Algorithms
Two Pointer
Bitmask
Beginner
Discrete Logarithm/Shank‘s Baby-step Giant-step Algorithm
Greedy
Divide and Conquer
Dynamic Programming
Tag it!
laimao很喜欢这首“BigBang”里的“Soft Kitty”,这首歌的歌词很简单只有6句,"soft kitty, warm kitty, little ball of fur,happy kitty, sleepy kitty, purr purr purr.",她总是唱着玩儿。现在她无聊了决定换一个玩法,你来说出一个数字n,她来唱出第n(1 ≤ n ≤ 10^9)句歌词。注意了她的唱法是,第i次唱这首歌时,每句歌词重复2^(i-1)次。就是像这样,“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 fur, little ball of fur,……”你能帮助她输出第n句歌词么(不包括标点)?
Input
多组数据,第一行是一个整数K(0<K<=100),表示数据组数。接下来K行,每行一个数字n,表示你需要输出第n句歌词。
Output
输出对应歌词
Sample Input
8 1 2 3 4 5 6 7 8
Sample Output
soft kitty warm kitty little ball of fur happy kitty sleepy kitty purr purr purr soft kitty soft kitty 错误点分析:前缀和计算时出错,数据范围没有考虑好,要用longlong用了int 解题思路:用前缀和的下标来映射唱n首歌。
#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 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; }