再求f(x,n)

再求f(x,n)

链接:http://ybt.ssoier.cn:8088/problem_show.php?pid=1167

【题目描述】

已知

用递归函数求解。

【输入】

第一数是x的值,第二个数是n的值。

【输出】

函数值。

【输入样例】

1 2

【输出样例】

0.40
#include <iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
double h(int x,int n){
    if(n==1) return 1.0*x/(1+x);

    return 1.0*x/(n+h(x,n-1));
}
int main(){

    double x,n;
    cin>>x>>n;
    printf("%.2f",h(x,n));

}
时间: 2024-08-07 00:15:56

再求f(x,n)的相关文章

hdu 1588 求f(b) +f(k+b) +f(2k+b) +f((n-1)k +b) 之和 (矩阵快速幂)

g(i)=k*i+b; 0<=i<nf(0)=0f(1)=1f(n)=f(n-1)+f(n-2) (n>=2)求f(b) +f(k+b) +f(2*k+b) +f((n-1)*k +b) 之和 Sample Input2 1 4 100 // k b n MOD2 0 4 100 Sample Output2112 矩阵A      相当于 1 1          f(2)  f(1) 1 0          f(1)  f(0) | 1       1| ^b          |

求f(k)=k^k(k=1...n)的前n项和

求f(k)=k^k(k=1...n)的前n项和. 程序实现: #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> long long My_Mul_Sum(int *n)//封装了一个求k^k的前n项和的函数 { int k = 1; long long sum = 0;//定义为long long是为了防止数据较大,容易溢出 for (k = 1; k <= n; k++) { int count = 0, mul = 1;//count

1128: 零起点学算法35——再求多项式(含浮点)

1128: 零起点学算法35--再求多项式(含浮点) Time Limit: 1 Sec  Memory Limit: 64 MB   64bit IO Format: %lldSubmitted: 2141  Accepted: 1002[Submit][Status][Web Board] Description 输入一个整数n,计算 1+1/(1-3)+1/(1-3+5)+...+1/(1-3+5-...+2n-1)的值 Input 输入一个整数n(多组数据) Output 出1+1/(1

poj 3592 Instantaneous Transference 强连通图 缩点 再求最长路

1 #include<iostream> 2 #include<stdio.h> 3 #include<string.h> 4 #include<stack> 5 #include<queue> 6 using namespace std; 7 #define maxx 44 8 #define maxx2 44*44 9 #define INF 99999999 10 char s[maxx][maxx]; 11 bool tong[maxx2

YT14-HDU-三分查找求F(x)的最小值

Problem Description Now, here is a fuction: F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=100) Can you find the minimum value when x is between 0 and 100. Input The first line of the input contains an integer T(1<=T<=100) which means the numb

求f(x,n)

求f(x,n) 链接: http://ybt.ssoier.cn:8088/problem_show.php?pid=1166 [题目描述] 已知 计算x=4.2,n=10以及x=2.5,n=15时的f的值. [输入] 输入x和n. [输出] 函数值,保留两位小数. [输入样例] 4.2 10 [输出样例] 3.68 #include <iostream> #include<stdio.h> #include<math.h> using namespace std; d

一本通1166 求f(x,n)

[题目描述] 已知 计算x=4.2,n=1以及x=2.5,n=15时f的值. [输入] 输入x和n. [输出] 函数值,保留两位小数. [输入样例] 4.2 10 [输出样例] 3.68 1.看见这种一个套着一个还带着诡异符号的, 基本上都是函数+循环(递归嘛)的套路. 话说这题一开始我没看明白, 从n怎么变到x+1的??? 再看看, 好像是由n变到1,然后最后那个根号里面有个x: 让我们递归一下,写写代码.2.这就是正解了 #include<iostream> #include<cst

使用递归和非递归求f(m,n)

递归方法如下: int f(int m, int n) { if (1 == m) { return n; } else if (1 == n) { return m; } return f(m, n - 1) + f(m - 1, n); } 非递归方法如下: int f(int m, int n) { int a[100][100]; for (int i = 0; i < m; ++i) { a[i][0] = i + 1; } for (int i = 0; i < n; ++i) {

输入几个分数,去除最高2个,最低2个,求和以后再求平均分(5个以上)

Console.WriteLine("请输入分数的个数:"); int a = Convert.ToInt32(Console.ReadLine()); int [] fs = new int [a]; if (a < 5) { Console.WriteLine("输入的分数至少为5个!"); } else { for (int i = 0; i < a; i++) { Console.WriteLine("请输入第{0}个分数:"