Codeforces 513C Second price auction 数学公式求期望
来源:互联网 发布:美帝 知乎 编辑:程序博客网 时间:2024/05/16 07:22
题目大意:
就是n个公司(n <= 5个)分别自己出价, 每个公司出的价格随即在[Li, Ri]之间的任意一个整数(1 <= Li <= Ri <= 10000), 问随机出来的5个数中第二大的数的期望是多少
大致思路:
纯数学推理做的...有点厉害的样子...
数学公式见代码注释
代码如下:
Result : Accepted Memory : 4 KB Time : 15 ms
/* * Author: Gatevin * Created Time: 2015/2/26 10:22:50 * File Name: poi~.cpp */#include<iostream>#include<sstream>#include<fstream>#include<vector>#include<list>#include<deque>#include<queue>#include<stack>#include<map>#include<set>#include<bitset>#include<algorithm>#include<cstdio>#include<cstdlib>#include<cstring>#include<cctype>#include<cmath>#include<ctime>#include<iomanip>using namespace std;const double eps(1e-8);typedef long long lint;/* * E = ∑b*P(b) * P(b)表示第二大的数是b的概率 * P(b)的计算公式如下, 参考Codeforces第三种解法的计算公式(官方那个我看的时候有点问题) * (这里用II表示连乘, ∑表示累和) * P(b) = P(max = b, second = b) + P(max > b, second = b) * P(max = b, second = b) = P(max <= b) - P(max < b) - P(max = b, second < b) * = IIP(ri <= b) - IIP(ri < b) - ∑P(ri = b)*IIP(rj < b) (j != i) * P(max > b, second = b) = ∑P(ri > b)*(IIP(rj <= b) - IIP(rj < b)) (j != i) */int n, L[6], R[6];double Less(int j, int i)//return P(rj <= i){ if(i < L[j]) return 0; if(i >= R[j]) return 1.; else return (i - L[j] + 1.)/(R[j] - L[j] + 1.);}double equal(int j, int i)//return P(rj == i){ if(i < L[j] || i > R[j]) return 0; else return 1./(R[j] - L[j] + 1.);}double more(int j, int i)//return P(rj > i){ if(i >= R[j]) return 0; if(i < L[j]) return 1.; return (R[j] - i)/(R[j] - L[j] + 1.);}int main(){ scanf("%d", &n); int ml = 10010, mr = 0; double ans = 0; for(int i = 1; i <= n; i++) { scanf("%d %d", L + i, R + i); ml = min(ml, L[i]); mr = max(mr, R[i]); } for(int i = ml; i <= mr; i++) { double p1 = 0; double p11 = 1, p12 = 1, p13 = 0; for(int j = 1; j <= n; j++)//这些O(n*n)的部分其实可以预处理降低复杂度 { p11 *= Less(j, i), p12 *= Less(j, i - 1);//IIP(ri <= b) 和 IIP(ri < b) double tmp = equal(j, i); for(int k = 1; k <= n; k++) if(k != j) tmp *= Less(k, i - 1); p13 += tmp;// ∑P(ri = b)*IIP(rj < b) } p1 = p11 - p12 - p13;//P(max = b, second = b) double p2 = 0; for(int j = 1; j <= n; j++) { double tmp1 = more(j, i); double tmp2 = 1., tmp3 = 1.; for(int k = 1; k <= n; k++) if(k != j) tmp2 *= Less(k, i), tmp3 *= Less(k, i - 1); p2 += tmp1*(tmp2 - tmp3);//P(max > b, second = b) = ∑P(ri > b)*(IIP(rj <= b) - IIP(rj < b)) } ans += (p1 + p2)*i; } printf("%.10f\n", ans); return 0;}
0 0
- Codeforces 513C Second price auction 数学公式求期望
- Codeforces 513C Second price auction 概率dp 求期望
- Second price auction - CodeForces 513 C 概率期望
- Codeforces 513C Second price auction (bruteforce)
- codeforces Second-Price Auction
- codeforces Rockethon 2015 C. Second price auction 概率
- 【打CF,学算法——三星级】CodeForces 513C Second price auction (进制状态表示)
- Second-price Auction
- Second-price Auction
- Codeforces386A. Second-Price Auction
- Second-price Auction
- zoj3202 Second-price Auction
- ZOJ3202-Second-price Auction
- A. Second-price Auction
- rockethon2015 C题 Second price auction 概率dp
- zoj 3202 Second-price Auction
- ZOJ 3202 Second-price Auction
- zoj 3202 Second-price Auction
- linux关闭ipv6
- iOS开发之静态库.a的制作教程
- 浅一谈百度索引量和收录量的区别
- Flex 数据四舍五入保留N位有效数字
- 如何将PDF转换为PPT格式
- Codeforces 513C Second price auction 数学公式求期望
- Ubuntu 14.10 / Linux Mint 17.1 解决Android模拟器运行黑屏无响应的问题
- 工业控制元器件介绍
- 配合angular的框架
- codeforces 518D Ilya and Escalator
- java中的匿名内部类总结
- 笔记
- cario在virsual studio中的配置
- 技术员转型之路分析