根据概率公式dfs即可,判断和区间[T-E,T+E]是否有交,控制层数。
#include<bits/stdc++.h> using namespace std; int K,R,L; double P,E,T; double Lt,Rt; double dfs(double L,double R,int k = 0) { if(R<Lt || L>Rt) return 0; if(Lt < L && R < Rt) return 1; double H = (L+R)/2; if(k == K) return (Lt<H && H<Rt)?1.:0.; double p = T<H?1-P:P; return dfs(L,H,k+1)*p + dfs(H,R,k+1)*(1.-p); } //#define LOCAL int main() { #ifdef LOCAL freopen("in.txt","r",stdin); #endif scanf("%d%d%d",&K,&L,&R); scanf("%lf%lf%lf",&P,&E,&T); Lt = T-E, Rt = T+E; printf("%lf ",dfs(L,R)); return 0; }