CodeForces 668C Little Artem and Random Variable(数学)
来源:互联网 发布:股票价值分析软件 编辑:程序博客网 时间:2024/05/29 02:53
题意:有两个骰子,每个骰子有n面,现在你需要求每个骰子扔到每一面的概率是多少,现在给你扔到min(a,b)=i的概率和max(a,b)=i的概率。
思路:由题意知道P(max(a,b))=i P(min(a,b))=i
那么显然可以推导出来
P(max(a,b)<=i) = P(a<=i)*P(b<=i)
P(min(a,b)>=i) = P(a>=i)*P(b>=i) = (1-P(a<=i-1))*(1-P(b<=i-1))
上面那个式子可以推导出P(a<=i)+P(b<=i)=1+P(a<=i)*P(b<=i)-P(min(a,b)>=i+1)
同时P(a=i) = P(a<=i) - P(a<=i-1),然后就是记录Pmax的前缀和和Pmin的后缀和解方程就可以了
#include<bits/stdc++.h>using namespace std;const int maxn = 1e6+7;double prea[maxn],preb[maxn],a[maxn],b[maxn];int main(){ int n; scanf("%d",&n); for (int i = 1;i<=n;i++) scanf("%lf",&prea[i]); for (int i = 1;i<=n;i++) scanf("%lf",&preb[i]); for (int i = 1;i<=n;i++) prea[i]+=prea[i-1]; for (int i = n;i;i--) preb[i]+=preb[i+1]; for (int i = 1;i<=n;i++) { double aa = 1; double bb = -(1+prea[i]-preb[i+1]); double cc = prea[i]; double delta = max(bb*bb-4*aa*cc,0.0); a[i] = (-bb-sqrt(delta)) / (2*aa); b[i] = (-bb+sqrt(delta)) / (2*aa); } for (int i = 1;i<=n;i++) printf("%lf ",a[i]-a[i-1]); printf("\n"); for (int i = 1;i<=n;i++) printf("%lf ",b[i]-b[i-1]); printf("\n");}
0 0
- CodeForces 668C Little Artem and Random Variable(数学)
- CF 668C(Little Artem and Random Variable-概率)
- CF 668C Little Artem and Random Variable
- codeforces 641D. Little Artem and Random Variable
- Codeforces #669 Div2 C. Little Artem and Matrix(模拟)
- CodeForces 669C Little Artem and Matrix(暴力)
- CodeForces 641 C.Little Artem and Dance(水~)
- codeforces 669C Little Artem and Matrix
- CodeForces 668B Little Artem and Dance
- CodeForces 668A Little Artem and Matrix
- codeforces#348-C. Little Artem and Matrix-模拟
- Codeforces 669C Little Artem and Matrix (模拟)
- CodeForces 641C Little Artem and Dance (模拟)
- Codeforces 669C Little Artem and Matrix【思维+暴力】
- Codeforces Round #348 (div 2) C. Little Artem and Matrix
- Codeforces #669 Div2. D. Little Artem and Dance(思维)
- 【CodeForces】669A - Little Artem and Presents(找规律)
- CodeForces 641 A.Little Artem and Grasshopper(水~)
- 机器学习之——归一化线性回归与归一化逻辑回归
- js 弹出确认 取消对话框
- hibernate之实体粒度设计
- hdu 1688 Sightseeing
- @RequestParam @RequestBody @PathVariable
- CodeForces 668C Little Artem and Random Variable(数学)
- Maven项目有工程报错,但是不影响运行
- 面试题12
- 单点登录系统
- Unity5打包assetbundle
- python的各种模块安装及其两个版本一起安装
- Java Web 与 QtQuick
- JDBC的增删改查
- 设计模式——桥接模式