C. Little Artem and Random Variable

题目连接:

http://www.codeforces.com/contest/668/problem/C

Description

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 two dices. When thrown each dice shows some integer from 1 to n inclusive. For each dice the probability of each outcome is given (of course, their sum is 1), and different dices may have different probability distributions.

We throw both dices simultaneously and then calculate values max(a, b) and min(a, b), where a is equal to the outcome of the first dice, while b is equal to the outcome of the second dice. You don't know the probability distributions for particular values on each dice, but you know the probability distributions for max(a, b) and min(a, b). That is, for each x from 1 to n you know the probability that max(a, b) would be equal to x and the probability that min(a, b) would be equal to x. Find any valid probability distribution for values on the dices. It's guaranteed that the input data is consistent, that is, at least one solution exists.

Input

First line contains the integer n (1 ≤ n ≤ 100 000) — the number of different values for both dices.

Second line contains an array consisting of n real values with up to 8 digits after the decimal point — probability distribution for max(a, b), the i-th of these values equals to the probability that max(a, b) = i. It's guaranteed that 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 format.

Output

Output two descriptions of the probability distribution for a on the first line and for b on the second line.

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

Sample Input

2

0.25 0.75

0.75 0.25

Sample Output

0.5 0.5

0.5 0.5

Hint

题意

有两个骰子,每个骰子有n面,现在你需要求每个骰子扔到每一面的概率是多少

现在给你扔到min(a,b)=i的概率和max(a,b)=i的概率。

题解:

解方程 p[i]是第一个前缀和,q[i]是第二个的后缀和

所以 prea[i]*preb[i] = p[i]

(1-prea[i])(1-preb[i]) = q[i+1]

然后解出来这个方程就好了

prea[i]和preb[i]指的是a[i],b[i]前缀和的意思。

代码

#include<bits/stdc++.h>
using namespace std; const int maxn = 1e6+7; double a[maxn],b[maxn],c[maxn],d[maxn]; int main()
{
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%lf",&a[i]);
for(int i=1;i<=n;i++)
scanf("%lf",&b[i]);
for(int i=1;i<=n;i++)a[i]=a[i-1]+a[i];
for(int i=n;i;i--)b[i]=b[i+1]+b[i];
for(int i=1;i<=n;i++)
{
double A = 1;
double B = -(1+a[i]-b[i+1]);
double C = a[i];
double delta = max(B*B - 4*A*C,0.0);
c[i] = (-B+sqrt(delta))/(2*A);
d[i] = (-B-sqrt(delta))/(2*A);
}
for(int i=1;i<=n;i++)
printf("%.6f ",c[i]-c[i-1]);
printf("\n");
for(int i=1;i<=n;i++)
printf("%.6f ",d[i]-d[i-1]);
printf("\n");
}

Codeforces Round #348 (VK Cup 2016 Round 2, Div. 1 Edition) C. Little Artem and Random Variable 数学的更多相关文章

  1. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) D. Little Artem and Dance

    题目链接: http://codeforces.com/contest/669/problem/D 题意: 给你一个初始序列:1,2,3,...,n. 现在有两种操作: 1.循环左移,循环右移. 2. ...

  2. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) E. Little Artem and Time Machine 树状数组

    E. Little Artem and Time Machine 题目连接: http://www.codeforces.com/contest/669/problem/E Description L ...

  3. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) D. Little Artem and Dance 模拟

    D. Little Artem and Dance 题目连接: http://www.codeforces.com/contest/669/problem/D Description Little A ...

  4. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) C. Little Artem and Matrix 模拟

    C. Little Artem and Matrix 题目连接: http://www.codeforces.com/contest/669/problem/C Description Little ...

  5. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) B. Little Artem and Grasshopper 模拟题

    B. Little Artem and Grasshopper 题目连接: http://www.codeforces.com/contest/669/problem/B Description Li ...

  6. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) A. Little Artem and Presents 水题

    A. Little Artem and Presents 题目连接: http://www.codeforces.com/contest/669/problem/A Description Littl ...

  7. Codeforces Round #348(VK Cup 2016 - Round 2)

    A - Little Artem and Presents (div2) 1 2 1 2这样加就可以了 #include <bits/stdc++.h> typedef long long ...

  8. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) D

    D. Little Artem and Dance time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  9. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) C

    C. Little Artem and Matrix time limit per test 2 seconds memory limit per test 256 megabytes input s ...

随机推荐

  1. python 实现字符串转整型

    def str2Int(s): l=list(s) if len(l)<=0: return 0 flag=0 sum=0 dict_num={':9} dict_tag={'+':1,'-': ...

  2. 五. Jmeter--HTTP Cookie Manager

    1. 添加HTTP Cookie Manager 2.添加登录login http,request info 和 HTTP Header Manager 中的信息是从fiddler中拿的, 至于hea ...

  3. OGG生成数据定义文件的参数NOEXTATTR

    ./defgen paramfile ./dirprm/jzjj.prm NOEXTATTR In OGG 11.2, there is a new parameter NOEXTATTR. This ...

  4. i春秋第二届春秋欢乐赛RSA256writeup

    i春秋第二届春秋欢乐赛writeup 下载之后进行解压 发现四个文件 0x01看到题目是RSA的  又看到public.key 所以直接用kali linux的openssl 0x02可以看到e就是E ...

  5. 无状态Http

    无状态的根本原因 浏览器和服务器使用socket通信,服务器将请求结果返回给浏览器后,会关闭当前socket连接.而且服务器会在处理页面完毕后销毁页面对象. 应用层面的原因 浏览器和服务器之间通信都遵 ...

  6. Sklearn-GridSearchCV网格搜索

    GridSearchCV,它存在的意义就是自动调参,只要把参数输进去,就能给出最优化的结果和参数.但是这个方法适合于小数据集,一旦数据的量级上去了,很难得出结果.这个时候就是需要动脑筋了.数据量比较大 ...

  7. Linux下的格式化字符串漏洞利用姿势

    linux最早的漏洞防护机制nx-stack刚刚出现后就有人想出了突破方法.那就是只有栈是不可执行,而除了栈以外的其他地方还是可以执行的,只要把返回地址执行别的地方就可以. 一.格式化字符串漏洞 格式 ...

  8. 找到最大或最小的N个元素---heapq模块

    堆排序heapq的用法 基本用法: 复杂数据结构: # coding=utf- # example.py # Example of using heapq to find the N smallest ...

  9. vue 阻止事件冒泡

    <mt-button type="danger" size="small"  @click="cancelOrderInfo(this.even ...

  10. BNUOJ 52517 Another Server

    网络流. 似乎有别的做法,没想. #include<bits/stdc++.h> using namespace std; + ; const int INF = 0x7FFFFFFF; ...