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. 健身VS不健身,完全是两种不同的人生!

    这两天一组同龄人合照 刷爆了国内健身圈, 图左是一位67岁的老人, 图右是67岁的健美运动员杨新民老师 相同年龄, 但从外观上有着强烈的距离感! 让多人不禁感叹,健身和不健身, 简直就是两种状态,两种 ...

  2. RAID总结

    RAID-0: 这种模式若使用相同型号容量的磁盘来组成效果最佳.这种模式RAID会先将磁盘切出等量的区块chunk,当文件要存入RAID时先按照chunk的大小切割好,再依次存放到各个磁盘中去,由于磁 ...

  3. juery获取元素的方法

    1 从集合中通过指定的序号获取元素 html: 复制代码 代码如下: <div> <p>0</p> <p>1</p> <p>2& ...

  4. Linux 上配置 NTP SERVER

    在CENTOS 6.2上面安装配置NTP SERVER 安装NTP:yum install ntp 配置时间源vi /etc/ntp.confserver 210.72.145.44server nt ...

  5. ACM ICPC Kharagpur Regional 2017

    ACM ICPC Kharagpur Regional 2017 A - Science Fair 题目描述:给定一个有\(n\)个点,\(m\)条无向边的图,其中某两个点记为\(S, T\),另外标 ...

  6. Tutorial 7: Schemas & client libraries

    转载自:http://www.django-rest-framework.org/tutorial/7-schemas-and-client-libraries/ Tutorial 7: Schema ...

  7. 开源介绍:Google Guava、Google Guice、Joda-Time

    一.Guava 是一个 Google 的基于java1.6的类库集合的扩展项目,包括 collections, caching, primitives support, concurrency lib ...

  8. xshell 映射带跳板机服务器的端口到本地

    1.配置xshell连接跳板机服务器: 2. 3.可用navicate等同过端口连接远程数据库.

  9. [ python ] 变量及基础的数据类型

    python2 和 python3 不同的编码方式 python2 默认编码方式是 ascii码 python3 默认编码方式是 utf-8 具体表现为:当 python3 和 python2 在打印 ...

  10. SaltStack的salt-ssh使用及LAMP状态设计部署(五)

    一.salt-ssh的使用 官方文档:https://docs.saltstack.com/en/2016.11/topics/ssh/index.html (1)安装salt-ssh [root@l ...