Codeforces Round #348 (VK Cup 2016 Round 2, Div. 1 Edition) C. Little Artem and Random Variable 数学

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 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 thatmax(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 formax(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 than10 - 6.

Examples

input

20.25 0.750.75 0.25

output

0.5 0.5 0.5 0.5 

题意:

    

  两个一样的骰子n个面 (1-n)

  并且给你max(a,b)=i和min(a,b)=i的概率

  让你求a,b分别是i的概率

题解:

  

  设定骰子前i个面的概率前缀和为q[i],后缀为p[i]

  那么我们可以得到

  q[i]*p[i] = a[i]的前缀和

  (1-q[i])*(1-p[i]) = b[i+1]的后缀和

  合并化简可以得到  p[i] + q[i] = 1+a[i] - b[i+1];  用这三个式子求就好了

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1e5+10, M = 1e3+10, mod = 1000000, inf = 1e9+1000;
typedef long long ll;

double a[N],b[N],p[N],q[N];
int n;
int main() {
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%lf",&a[i]);
    for(int j=1;j<=n;j++) scanf("%lf",&b[j]);
    for(int i=1;i<=n;i++) a[i] = a[i-1] + a[i];
    for(int i=n;i>=1;i--) b[i] = b[i] + b[i+1];
    for(int i=1;i<=n;i++) {
        double B = b[i+1] - a[i] - 1;
        double dd = sqrt(max(B*B-4*a[i],0.));
        p[i] = (-B+dd)/2;
        q[i] = (-B-dd)/2;
    }
    for(int i=1;i<=n;i++) cout<<q[i]-q[i-1]<<" "; cout<<endl;
    for(int i=1;i<=n;i++) cout<<p[i]-p[i-1]<<" ";
    return 0;
}
时间: 2024-12-22 17:52:55

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

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 ll; const int N = 1e5 + 5; int main() { int n; scanf ("%d", &n); int ans = n / 3 * 2; if (n % 3) { ans++; } printf ("%d\n", ans);

Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition)

A. Bear and Game 题意:一个体育节目,它可能在某一分钟是很有趣的,其他时间都是很无聊的,如果持续十五分钟都很无聊的话那么Bear就会关掉电视,问什么时候会关掉电视. 题解:用第i个有趣的时间减去第i-1个有趣的时间,如果差值大于十五分钟那就输出第i个有趣的时间+15.注意第一个有趣的时间要为0,最后一个为90. 代码: 1 /*A*/ 2 #include<cstdio> 3 using namespace std; 4 5 const int maxn=95; 6 7 int

Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) B

#include<stdio.h> #include<algorithm> #include<vector> #include<string.h> using namespace std; int main() { int n,m,i; while(scanf("%d%d",&n,&m)!=EOF) { vector<int> da,xi; int a,b; int maxa=1,minb=n; for(i=1

Codeforces Round #412 (rated, Div. 2, base on VK Cup 2017 Round 3) B. T-Shirt Hunt

B. T-Shirt Hunt time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Not so long ago the Codecraft-17 contest was held on Codeforces. The top 25 participants, and additionally random 25 participant

【树形dp】Codeforces Round #405 (rated, Div. 1, based on VK Cup 2017 Round 1) B. Bear and Tree Jumps

我们要统计的答案是sigma([L/K]),L为路径的长度,中括号表示上取整. [L/K]化简一下就是(L+f(L,K))/K,f(L,K)表示长度为L的路径要想达到K的整数倍,还要加上多少. 于是,我们现在只需要统计sigma((L+f(L,K))),最后除以K即可. 统计sigma(L)时,我们考虑计算每条边出现在了几条路径中,设u为edgei的子节点,那么这条边对答案的贡献就是siz(u)*(n-siz(u)),siz(u)为u的子树大小. 统计sigma(f(L,K))时,我们需要dp出

Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) B

Description Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pictures). There are n members, numbered 1 through n. m pairs of members are friends.

Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) C

Description In the army, it isn't easy to form a group of soldiers that will be effective on the battlefield. The communication is crucial and thus no two soldiers should share a name (what would happen if they got an order that Bob is a scouter, if

VK Cup 2017 Round 3 + Codeforces Round #412

A 读题题 B 就是你排名第p,得了x分,而最终至少需要y分,你需要最少的successful hack,使得最终得分s>=y,且由s随机取25个数,使p被选中. (1)暴力枚举hack成功几次,失败几次就好了 (2)另解:枚举尽可能小的s,使|s-x|=0(mod 50),分类讨论 If s?≤?x, we need 0 successful hacks, since we can just make (x?-?s)?/?50 unsuccessful hacks. If s?>?x and

Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) A

Description Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob. Right now, Limak and Bob weigh a and b respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.