邀請賽隊員選拔賽–二分

來源:互聯網
上載者:User
文章目錄
  • 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;        }    }}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.