Codeforces Round #348 (VK Cup Round 2, Div. 1 Edition) c. Little Artem and Random Variable Math

Source: Internet
Author: User

C. Little Artem and Random Variable

Little Artyom decided to study probability theory. He found a book with a lot of nice exercises and now wants you to help him with one of them.

Consider, dices. When thrown all dice shows some integer from 1 to n inclusive. For each dice the probability of each outcome are given (of course, their sum is 1), and different dices could have Diffe Rent probability distributions.

We throw both dices simultaneously and then calculate valuesMax(a,b) andmin(a,b), whereais equal to the outcome of the first dice, whilebis equal to the outcome of the second dice. You don ' t know the probability distributions for particular values in each dice, but you know the probability distribution S for Max(a, b) and min(a, b). That's, for each x from 1 to n know the probability thatmax(a< /c15>, b) would is equal to x and the probability that min(a, b ) would is equal to x. Find any valid probability distribution for values on the dices. It's guaranteed that's the input data is consistent, that's, at least one solution exists.

Input

First line contains the integer n (1≤ n ≤100)-the number of different values for both di CES.

Second line contains a array consisting of n Real values with up to 8 digits after the decimal point-prob Ability distribution forMax(a, b), the i-th of these values equals to the P Robability that Max(a, b) = I. It's guaranteed the sum of these values for one dice is 1. The third line contains the description of the distribution min(a, b) in the same fo Rmat.

Output

Output of descriptions of the probability distribution for a in the first line and for b on the Second line.

The answer is considered correct if each value of Max (a, b) and min (a, b) Probability distribution values does not differ by + than -6 from ones given in input. Also, probabilities should is non-negative and their sums should differ from 1 to no more than -6.

Examples input
2
0.25 0.75
0.75 0.25
Output

Test Instructions:Two identical dice n Faces (1-n) and give you Max (A, B) =i and Min (A, B) the probability of =i you to ask a A, B, respectively is the probability of IThe following:Set the probability prefix of the first face of the dice and q[i], suffix p[i] then we can get q[i]*p[i] = a[i] prefix and (1-q[i]) * (1-p[i]) = b[i+1] The suffix and merge simplified can get p[i] + q[i] = 1+a[i  ]-b[i+1]; Just use these three formulas.
#include <iostream>#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>using namespacestd;Const intN = 1e5+Ten, M = 1e3+Ten, mod =1000000, INF = 1e9+ +; typedefLong Longll;DoubleA[n],b[n],p[n],q[n];intN;intMain () {scanf ("%d",&N);  for(intI=1; i<=n;i++) scanf ("%LF",&A[i]);  for(intj=1; j<=n;j++) scanf ("%LF",&B[j]);  for(intI=1; i<=n;i++) A[i] = a[i-1] +A[i];  for(inti=n;i>=1; i--) B[i] = B[i] + b[i+1];  for(intI=1; i<=n;i++) {        DoubleB = b[i+1]-A[i]-1; Doubledd = sqrt (max (b*b-4*a[i],0.)); P[i]= (-B+DD)/2; Q[i]= (-B-DD)/2; }     for(intI=1; i<=n;i++) cout<<q[i]-q[i-1]<<" "; cout<<Endl;  for(intI=1; i<=n;i++) cout<<p[i]-p[i-1]<<" "; return 0;}

Codeforces Round #348 (VK Cup Round 2, Div. 1 Edition) c. Little Artem and Random Variable Math

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.