邀请赛队员选拔赛--二分

二分+平移

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'.

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

lisi
#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;
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值