求二分次数的期望
dfs搜
最后的答案有n种情况
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <cmath>
using namespace std;
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <deque>
#include <map>
#define cler(arr, val) memset(arr, val, sizeof(arr))
typedef long long LL;
const int MAXN = 110;
const int MAXM = 140000;
const int INF = 0x3f3f3f3f;
const LL mod = 10000007;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
int dfs(int l,int r,int num)
{
if(l>r) return 0;
int m=(l+r)>>1,ans=0;
ans+=num;//猜中
ans+=dfs(l,m-1,num+1);//左边
ans+=dfs(m+1,r,num+1);//右边
return ans;
}
int main()
{
int n;
while(cin>>n)
{
printf("%.2lf\n",dfs(1,n,1)*1.0/n);
}
}