http://codeforces.com/problemset/problem/335/E (题目连接)ios
懒得写了= =spa
这题咋不上天= =。.net
参考题解:http://blog.csdn.net/clover_hxy/article/details/62217674code
对于第一问,有另外一种比较容易懂的想法:blog
假设Bob即将走一条高度为h的溜索(此时他所在的大楼高度>=h),这条溜索的长度指望是多少?get
此时Bob站在这条溜索的左端点,而未知的部分只有溜索越过的大楼和溜索的右端点。换句话说,这条溜索指望增长多少栋大楼?string
容易发现,某栋大楼高度>=h的几率是1/(2^h)。即,在2^h栋楼中才指望出现一个高度>=h的楼。于是,这条高度为h的溜索的指望长度是2^h。it
也就是说,一条花费2^h的溜索的指望长度是2^h。因为Bob的计数器一开始是1,因此很容易得出,大楼数的指望就是计数器最终的值n。io
——wmdcstdioclass
?
// codeforces 335E #include<algorithm> #include<iostream> #include<cstdlib> #include<cstring> #include<cstdio> #include<cmath> #define LL long long #define Pi acos(-1.0) #define free(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout); using namespace std; //learn from clover_hxy char ch[10]; int n,h; int main() { scanf("%s",ch); scanf("%d%d",&n,&h); if (ch[0]=='B') {printf("%d",n);return 0;} double ans=n;double p=1; for (int i=1;i<=h;i++) { p*=2;double t=1; for (int j=1;j<=n;j++,t*=(1-1/p)) ans+=(n-j)/p/p*t*(p-p/2*(1+(j-1)/(p-1))); } printf("%.9lf",ans); return 0; }