2个n面骰子,骰子上的数为1~n
同时掷骰子,得到的数为a,b
已知
P(min(a,b)=i),P(max(a,b)=i)
求
P(a=i),P(b=i)
求出
ai=P(min(a,b)>=i),bi=P(max(a,b)<=i)
P(a<=i)P(b<=i)=P(max(a,b)<=i)=bi
P(a>=i)P(b>=i)=(1−P(a<=i−1))(1−P(<=i−1))
P(a<=i)+P(b<=i)=1+P(a<=i)P(b<=i)−P(a>=i+1)P(b>=i+1)=1+bi−ai+1
总之我们发现
P(a<=i),P(b<=i)
由
ai,bi
唯一确定
且必为一个1元2次方程的2个解
#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=Pre[x];p;p=Next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=Next[p])
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define SI(a) ((a).size())
typedef long long ll;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int read()
{
int x=0,f=1; char ch=getchar();
while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
#define N (100010)
double a[N],b[N];
double p[N],q[N];
int main()
{
// freopen("C.in","r",stdin);
// freopen(".out","w",stdout);
int n=read();
b[0]=a[n+1]=0;
a[0]=b[n+1]=1;
For(i,n) cin>>b[i];
For(i,n) cin>>a[i];
ForD(i,n-1) a[i]+=a[i+1]; //P(min(a,b)>=i)
Fork(i,2,n) b[i]+=b[i-1]; //P(max(a,b)<=i)
For(i,n) {
double c=1+b[i]-a[i+1],d=b[i];
double del=sqrt(abs(c*c-4*d));
double x1=(c+del)/2,x2=(c-del)/2;
p[i]=x1,q[i]=x2;
}
For(i,n) printf("%.10lf ",p[i]-p[i-1]);puts("");
For(i,n) printf("%.10lf ",q[i]-q[i-1]);
return 0;
}