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
output
OOOoOooOooooOoo

解题说明:数学题,找出斐波那契数列中的数字即可。

#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
using namespace std;

int m = 1, n = 1;
int main()
{
	int b;
	scanf("%d", &b);
	for (int i = 1; i <= b; ++i)
	{
		if (m == i)
		{
			int tmp = m + n;
			n = m;
			m = tmp;
			printf("O");

		}
		else printf("o");
	}
	return 0;

}


Here's the program that generates the (x,y) pairs for Euler's extrapolation with the given initial condition and slope equation: ```c++ #include <iostream> #include <cmath> namespace RungeKutta { double step(double x, double y, int n) { double h = x / n; for (int i = 1; i <= n; i++) { y = y + h * slope(x, y); x = x + h; } return y; } double *ones(int n, double v) { double *arr = new double[n]; for (int i = 0; i < n; i++) { arr[i] = v; } return arr; } double *linspace(double start, double end, int n) { double *arr = new double[n]; double h = (end - start) / (n - 1); for (int i = 0; i < n; i++) { arr[i] = start + i * h; } return arr; } double slope(double x, double y) { return (1 + 2 * x) * sqrt(y); } void extrapolate(double *x, double *y, int n) { for (int i = 0; i < n - 1; i++) { double h = x[i + 1] - x[i]; y[i + 1] = y[i] + h * slope(x[i], y[i]); } } void printXY(double *x, double *y, int n) { for (int i = 0; i < n; i++) { std::cout << "(" << x[i] << ", " << y[i] << ")" << std::endl; } } } int main() { const int n = 11; double *x = RungeKutta::linspace(0, 5, n); double *y = RungeKutta::ones(n, 1); y[n - 1] = RungeKutta::step(x[n - 2], y[n - 2], 2); RungeKutta::extrapolate(x, y, n); RungeKutta::printXY(x, y, n); delete[] x; delete[] y; return 0; } ``` Explanation: - The `RungeKutta` namespace contains the global functions required for the program. - The `step` function implements Euler's method to compute the value of `y` at a given `x` using the given slope equation. It takes three parameters: the current `x`, the current `y`, and the number of steps to take (`n`). It returns the final value of `y`. - The `ones` function creates an array of `n` elements with the same value (`v`). It takes two parameters: the number of elements (`n`) and the value to fill the array with (default is 1). - The `linspace` function creates an array of `n` equally spaced values between `start` and `end`. It takes three parameters: the starting value (`start`), the ending value (`end`), and the number of elements (`n`). - The `slope` function computes the slope at a given `(x, y)` pair using the given slope equation. It takes two parameters: the current `x` and the current `y`. - The `extrapolate` function computes the (x,y) pairs for Euler's extrapolation using the values of `x` and `y` computed so far. It takes three parameters: the array of `x` values, the array of `y` values, and the number of elements (`n`). - The `printXY` function prints the (x,y) pairs to the console. It takes three parameters: the array of `x` values, the array of `y` values, and the number of elements (`n`). - In the `main` function, we create an array of `x` values using the `linspace` function and an array of `y` values initialized to 1 using the `ones` function. We set the last element of `y` to the value computed using Euler's method with `n=2`. We then compute the remaining `(x,y)` pairs using Euler's extrapolation with the `extrapolate` function and print the results to the console using the `printXY` function. Finally, we delete the dynamically allocated arrays to free up memory.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值