【Codeforces 335 E】—Counting Skyscrapers
传送门
当询问 A l i c e Alice Alice的时候可以发现答案就是 n n n
因为考虑如果跳过一个高度为 i i i的
中间经过的楼房数量就是 2 i 2^i 2i
考虑枚举中间有几个房子等比数列算一下就可以得到了
考虑 B o b Bob Bob时
考虑枚举高度 i i i
即加入一个新的高度的绳子覆盖原来的
考虑枚举当前的长度 j j j
那么可能在 n − j n-j n−j个位置出现
概率是 ( n − j ) ( 1 − 1 2 i ) j − 1 ∗ 1 2 2 i (n-j)(1-\frac{1}{2^i})^{j-1}*\frac{1}{2^{2i}} (n−j)(1−2i1)j−1∗22i1
考虑减去覆盖的上一个高度的期望(再之前的已经被减去了)
i − 1 i-1 i−1的就是中间 j − 1 j-1 j−1个楼房中高度为 i − 1 i-1 i−1的个数的
个数就是 1 + ( j − 1 ) ∗ 1 2 i − 1 1+(j-1)*\frac{1}{2^i-1} 1+(j−1)∗2i−11

然后就完了
#include
using namespace std;
const int RLEN=1<<20|1;
inline char gc(){static char ibuf[RLEN],*ib,*ob;(ob==ib)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));return (ob==ib)?EOF:*ib++;
}
#define gc getchar
inline int read(){char ch=gc();int res=0,f=1;while(!isdigit(ch))f^=ch=='-',ch=gc();while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();return f?res:-res;
}
#define ll long long
#define re register
#define pii pair
#define fi first
#define se second
#define pb push_back
#define cs const
#define bg begin
template<class tp>inline void chemx(tp &a,tp b){a<b?a=b:0;}
template<class tp>inline void chemn(tp &a,tp b){a>b?a=b:0;}
int n,h;
double pw[73];
char s[10];
inline double ksm(double a,int b){double res=1;for(;b;b>>=1,a=a*a)if(b&1)res=res*a;return res;
}
int main(){scanf("%s",s+1);n=read(),h=read();if(s[1]=='A'){pw[0]=1;for(int i=1;i<=2*h;i++)pw[i]=pw[i-1]*0.5;double res=n;for(int i=1;i<=h;i++)for(int j=1;j<=n;j++)res+=1.0*(n-j)*ksm(1-pw[i],j-1)*pw[i*2]*((1<<i)-1.0*(1<<(i-1))*1.0*(1+1.0*(j-1)/((1<<i)-1)));printf("%.10f",res);}else cout<<n<<'\n';
}
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
