【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 nj个位置出现
概率是 ( 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}} (nj)(12i1)j122i1

考虑减去覆盖的上一个高度的期望(再之前的已经被减去了)
i − 1 i-1 i1的就是中间 j − 1 j-1 j1个楼房中高度为 i − 1 i-1 i1的个数的
个数就是 1 + ( j − 1 ) ∗ 1 2 i − 1 1+(j-1)*\frac{1}{2^i-1} 1+(j1)2i11

在这里插入图片描述

然后就完了

#include<bits/stdc++.h>
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<int,int>
#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';
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值