文章目錄
- Problem Description
- Input
- Output
- Sample Input
- Sample Output
- Author
二分+平移LOLTime Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other)Total Submission(s) : 46 Accepted Submission(s) : 7Font: Times New Roman | Verdana | GeorgiaFont Size: ← →Problem DescriptionThis year, Lisi loves a game named LOL. Now He comes up with a sequence which only contains the letter 'L' and 'o'. The sequence may like this:
L o o L o o o L o o L o o o o L o o L o o o L o o
Lisi described the sequence like this : let a(0) be a 3-character sequence "L o o". Then a longer a(k) is obtained by taking a copy of a(k-1), then "L o ... o" which contains k+2 o's, and then another copy of a(k-1). For example:
a(0) = "L o o"
a(1) = "L o o L o o o L o o"
a(2) = "L o o L o o o L o o L o o o o L o o L o o o L o o"
a(3) = "L o o L o o o L o o L o o o o L o o L o o o L o o L o o o o o L o o L o o o L o o L o o o o L o o L o o o L o o"
...
Now Lisi may ask you a question. For a given number k, in the sequence a(k) which letter is on k-th position, 'L' or 'o'. For example, k = 2, the second letter in the sequence a(2) is 'o'. Again, k = 4, the 4-th letter in the sequence a(4) is 'L'.
InputEach line will contain one interger k (1 <= k <= 10^9). Process to end of file.OutputFor each case please output a letter each line, either 'L' or 'o'.Sample Input
1357910111213
Sample Output
LoooooLoo
Authorlisi
#include<iostream>#include<cstdio>using namespace std;long long a[30];void init(){ a[0]=3; for(int i=1;i<=28;i++) a[i]=a[i-1] + i+3 + a[i-1]; }int main(){ init(); int k; while(cin>>k){ int pos = 0; while(1){ for(int i=0;i<=28;i++) if(a[i]>=k) { pos=i; break; } if(k>3 && pos>=1) k -= a[pos-1]; if(k==1){ printf("L\n"); break; } if(k>1 && k<=pos+3) { printf("o\n"); break; } k-=pos+3; } }}