[spojRNG]Random Number Generator
先将所有数加上Ri,即变为区间[0,2Ri],考虑容斥,将区间容斥为[0,+oo)-[2Ri,+oo),然后对[2Ri,+oo)令$bi=ai-2Ri$,相当于范围都是[0,+oo)
问题转化为求n个正无穷范围的数和不超过b的方案数,大胆猜测后发现就是$b^{n}/n!$,暴力累计即可
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define ld long double 4 int t,n,x,y,a[11]; 5 ld ans; 6 ld calc(int k){ 7 if (k<=0)return 0; 8 ld ans=1; 9 for(int i=1;i<=n;i++)ans=ans*k/i; 10 return ans; 11 } 12 int main(){ 13 scanf("%d",&t); 14 while (t--){ 15 scanf("%d%d%d",&n,&x,&y); 16 ans=0; 17 for(int i=0;i<n;i++){ 18 scanf("%d",&a[i]); 19 x+=a[i]; 20 y+=a[i]; 21 a[i]=a[i]*2; 22 } 23 for(int i=0;i<(1<<n);i++){ 24 int p=1,s=0; 25 for(int j=0;j<n;j++) 26 if (i&(1<<j)){ 27 p*=-1; 28 s+=a[j]; 29 } 30 ans+=p*(calc(y-s)-calc(x-s)); 31 } 32 for(int i=0;i<n;i++)ans/=a[i]; 33 printf("%.9Lf\n",ans); 34 } 35 }