1166:求f(x,n)
看起来有点意思的函数题,递归即可
想听题解推荐:《信息学奥赛一本通》题解_1166_求f(x,n)
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <forward_list>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cctype>
#define IOS {std::ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
#define x first
#define y second
#define int long long
#define end(x) {cout<<x<<'\n';return ;}
#define endy {cout<<"YES\n";return ;}
#define endn {cout<<"NO\n"; return }
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
const int N =2*1e5+10;
//string s;int n,x,y,i,j,k,l,r;float f;
double x,n;
//int a[N],b[N];
struct node{
int x,i;
};
void solve();
double f(double a,double b){
if(b==1) return sqrt(1+x);
return sqrt(f(a,b-1)+b);
}
void solve(){
cin>>x>>n;
double ans=f(x,n);
printf("%.2f",ans);
}
signed main(){
//IOS
int _=1;
//cin>>_;
while(_--)solve();
}
1167:再求f(x,n)
【输入样例】
1 2
【输出样例】
0.40
一样的,梅开二度
《信息学奥赛一本通》题解_1167_再求f(x,n)
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <forward_list>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cctype>
#define IOS {std::ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
#define x first
#define y second
#define int long long
#define end(x) {cout<<x<<'\n';return ;}
#define endy {cout<<"YES\n";return ;}
#define endn {cout<<"NO\n"; return }
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
const int N =2*1e5+10;
//string s;int n,x,y,i,j,k,l,r;float f;
double x,n;
//int a[N],b[N];
struct node{
int x,i;
};
void solve();
double f(double a,double b){
if(b==1) return x/(1+x);
return x/(f(a,b-1)+b);
}
void solve(){
cin>>x>>n;
double ans=f(x,n);
printf("%.2f",ans);
}
signed main(){
//IOS
int _=1;
//cin>>_;
while(_--)solve();
}