二分+平移
LOL
Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 46 Accepted Submission(s) : 7
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
This 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'.
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'.
Input
Each line will contain one interger k (1 <= k <= 10^9). Process to end of file.
Output
For each case please output a letter each line, either 'L' or 'o'.
Sample Input
1 3 5 7 9 10 11 12 13
Sample Output
L o o o o o L o o
Author
#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;
}
}
}