Codeforces Round #459(Div.2)

A. Eleven
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly n characters.

Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested that the i-th letter of her name should be 'O' (uppercase) if i is a member of Fibonacci sequence, and 'o' (lowercase) otherwise. The letters in the name are numbered from 1 to n. Fibonacci sequence is the sequence f where

  • f1 = 1,
  • f2 = 1,
  • fn = fn - 2 + fn - 1 (n > 2).

As her friends are too young to know what Fibonacci sequence is, they asked you to help Eleven determine her new name.

Input

The first and only line of input contains an integer n (1 ≤ n ≤ 1000).

Output

Print Eleven's new name on the first and only line of output.

Examples
input
8
output
OOOoOooO
input
15
outputOOOoOooOooooOoo
题意:输入一个数n,从1开始n,如果这个数是属于斐波那契数列的值其对应的字符为‘O’,否则为‘o’;
方法一:对斐波那契数列打表,在判断这个数是否为斐波那契数,(注意因为斐波那契数比较大所以不能用(dp[1000000]={0};dp[f[i]=1]))
 1 #include<bits/stdc++.h>
 2 #define ll long long
 3 using namespace std;
 4 const ll N=105;
 5 ll f[N];
 6 
 7 void fun(){
 8     f[1]=1;
 9     f[2]=1;
10     for(int i=3;i<N;i++){
11         f[i]=f[i-1]+f[i-2];
12     }
13 }
14 
15 bool cmp(int n){
16     for(int i=1;i<N;i++){
17         if(n==f[i]) return true;
18     }
19     return false;
20 }
21 
22 int main(){
23     int n;
24     cin>>n;
25     fun();
26     for(int i=1;i<=n;i++){
27         if(cmp(i))cout<<"O";
28         else cout<<"o"; 
29     }cout<<endl;
30 } 
方法二:斐波那契数列的本质是前两个数相加,所以可以利用(a+=b;swap(a,b);f[i]=b;)
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 
 4 int main(){
 5     int a=1,b=1;
 6     char P[105];
 7     int n;
 8     cin>>n;
 9     for(int i=1;i<n;i++)P[i]='o';
10     while(b<n){
11         P[b]='O';
12         a+=b;
13         swap(a,b);//swap()函数头文件:#include<algorithm>
14         P[b]='O'; 
15     }
16     for(int i=0;i<n;i++)cout<<P[i];
17 }

 

 

 

 
posted @ 2018-01-30 19:16  明楼  阅读(94)  评论(0)    收藏  举报