// 这很明显就是一个递归,递归的参数就是次数其实高度以及最后的长度 #include<stdio.h> #include<iostream> #include<vector> using namespace std; pair<float, float> dfs(float height , int count, float res) { // cout<<"h: "<<height<<" c: "<<count<<" res: "<<res<<endl; if(count == 0) { return {height,res}; } res+=height+height/2; count--; return dfs(height/2,count,res); } int main() { float height; while(cin>>height) { // cout<<height<<endl; auto res = dfs(height,5,0.f); printf("%g \n",res.second-res.first); // cout<<res.second-res.first<<endl; printf("%0.5f",res.first); } }