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. php常用函数——字符串函数

    php常用函数——字符串函数

  2. 内存不够清理方法,costdown项目时如果裁剪不下来,也可以参考

    Linux下清理内存和Cache方法 /proc/sys/vm/drop_caches 频繁的文件访问会导致系统的Cache使用量大增 $ free -m total used free shared ...

  3. openjudge-NOI 2.6-1768 最大子矩阵

    题目链接:http://noi.openjudge.cn/ch0206/1768/ 题解: 如果用O(n4)的算法肯定会炸,需要压缩掉一维的空间,只需要简单加和就好啦 例如,我们要对样例中第2-4行D ...

  4. Django项目上传到AWS服务器上

    EC2是亚马逊(Amazon.com)提供的弹性云计算服务:Apache是一个跨平台的Web服务器端软件,可以使Python.PHP.Perl等语言编写的程序运行在服务器上:Django是一个Web程 ...

  5. leetcode 之Valid Sudoku(七)

    判断行.列.九宫格内数字是否重复. 按照行.列.九宫格进行检查即可. bool validSudoku(const vector<vector<char>>& boar ...

  6. vim进阶-自己设置vim编辑器

    我这是最基础的一些vim设置,参考文章http://blog.csdn.net/huiguixian/article/details/6394095 看大牛设置的vim,感觉很花里胡哨,以后慢慢接触: ...

  7. Oracle表空间不足ORA-01654

    v在往数据表里插入数据时,出现了ORA-01654: 索引 SSERVICE.IX_MSI_WDR_INPUT_1 无法通过 1024 (在表空间 USERD 中) 扩展的错误信息,原来是数据量太大, ...

  8. poj1950 Dessert(DFS)

    题目链接 http://poj.org/problem?id=1950 题意 输入一个整数n(3<=n<=15),将1,2,..n顺序排列,在数字中间插入'+','-','.',这样会产生 ...

  9. cordova 整合 webpack vue

    cordova 是hybrid开发app的一个框架,通过js桥接原生api实现了js调用原生的一些功能:本打算学习下阿里的weex:可是一直打包不了,加上之前也用过cordova,打算使用cordov ...

  10. windows下怎样使用md命令一次建立多级子目录

    在Windows系统中一次只能够创建一个子目录,在命令提示符窗口则可以一次性创建多个子目录,例如如果想在f盘创建多级子目录,则md 23\13\65\45,后面的数字随便都可以.如果想一次性删除多级目 ...