HDU 5570:balls 期望。。。。。。。。。。。。。。。
balls
有nn个球,共有mm种颜色,第ii个球的颜色为jj的概率为\frac{a_{i,j}}{a_{i,1}+a_{i,2}+...+a_{i,m}}ai,1+ai,2+...+ai,mai,j。
对于第ii种颜色,若有xx个球,对答案的贡献为x^{2}x2。
问答案的期望。
若干组数据(大概55组)。
每组数据第一行两个整数n(1 \leq n \leq 1000), m(1 \leq m \leq 1000)n(1≤n≤1000),m(1≤m≤1000)。
接下来nn行每行mm个数表示a_i,j(1 \leq a_i,j \leq 100)ai,j(1≤ai,j≤100)
对于每组数组,输出一行表示答案,保留两位小数。
2 2
1 1
3 5
2 2
4 5
4 2
2 2
2 4
1 4
3.00
2.96
3.20
val[i][j]表示第i个球颜色为j的概率。那么第i个球颜色为j的期望E[x[i][j]]=val[i][j]*1+(1-val[i][j])*0=val[i][j]
c[i]表示颜色为i的球的个数。题目要求的是 sum(E[c[i]^2]) i的值从1到m。
从最简单的来看 如果要求的是E[c[i]],那么它等于E[(x[1][i]+x[2][i]...+x[n][i])]
现在要求的是E[c[i]^2]=E[(x[1][i]+x[2][i]...+x[n][i])^2]。
里面展开的话就是任意两个相乘,拿出其中一项来看 E[x[k1][i]*x[k2][i]]
若k1==k2,那这个等式等于=val[k1][i]
若k1!=k2,那这个等式等于=val[k1][i]*val[k2][i]
求和即是结果了。
代码:
#pragma warning(disable:4996)
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
using namespace std; const int maxn = 1005; int n, m;
double val[maxn][maxn]; int main()
{
//freopen("i.txt", "r", stdin);
//freopen("o.txt", "w", stdout); while (scanf("%d%d", &n, &m) != EOF)
{
for (int i = 1; i <= n; i++)
{
double sum = 0;
for (int j = 1; j <= m; j++)
{
scanf("%lf", &val[i][j]);
sum += val[i][j];
}
for (int j = 1; j <= m; j++)
{
val[i][j] = val[i][j] / sum;
}
}
double ans = 0;
for (int i = 1; i <= m; i++)
{
double sum = 0;
for (int j = 1; j <= n; j++)
{
sum += val[j][i];
ans += val[j][i];
ans -= val[j][i] * val[j][i];
}
ans += (sum*sum);
}
printf("%.2lf\n", ans);
}
//system("pause");
return 0;
}
HDU 5570:balls 期望。。。。。。。。。。。。。。。的更多相关文章
- HDU 5570 balls 期望 数学
balls Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5570 De ...
- hdu 5570 balls(期望好题)
Problem Description There are n balls with m colors. The possibility of that the color of the i-th b ...
- HDU 5810 Balls and Boxes(盒子与球)
Balls and Boxes(盒子与球) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/O ...
- HDU 5984 数学期望
对长为L的棒子随机取一点分割两部分,抛弃左边一部分,重复过程,直到长度小于d,问操作次数的期望. 区域赛的题,比较基础的概率论,我记得教材上有道很像的题,对1/len积分,$ln(L)-ln(d)+1 ...
- hdu 5810:Balls and Boxes(期望)
题目链接 这题似乎就是纯概率论.. E(V)=D(X_i)=npq (p=1/m,p+q=1) #include<bits/stdc++.h> using namespace std; t ...
- HDU 5810 Balls and Boxes (找规律)
Balls and Boxes 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5810 Description Mr. Chopsticks is i ...
- HDU 5810 Balls and Boxes 数学
Balls and Boxes 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5810 Description Mr. Chopsticks is i ...
- poj 2096 Collecting Bugs && ZOJ 3329 One Person Game && hdu 4035 Maze——期望DP
poj 2096 题目:http://poj.org/problem?id=2096 f[ i ][ j ] 表示收集了 i 个 n 的那个. j 个 s 的那个的期望步数. #include< ...
- HDU 4611 Balls Rearrangement 数学
Balls Rearrangement 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=4611 Description Bob has N balls ...
随机推荐
- centos默认安装mysql的默认密码
安装centos时选择安装Mysql 服务器 mysql的默认登录密码为空,但是直接登录的时候有报错: [root@localhost bin]# mysql -u root -pEnter pass ...
- X-Frame-Options报错处理
项目中用到iframe嵌入网页,因为是前后端分离的,所以前端会报错Refused to display ‘网址' in a frame because it set 'X-Frame-Options' ...
- composer install报错intervention/image 2.4.x-dev requires ext-fileinfo * -> the requested PHP extension fileinfo is missing from your system.
(1)问题:intervention/image 2.4.x-dev requires ext-fileinfo * -> the requested PHP extension fileinf ...
- centOs安装出现No package git available的解决办法
来源地址 [http://chinacheng.iteye.com/blog/1825538 ] centos安装git 下载源代码安装后,git clone出现“fatal unable to fi ...
- Vue基础笔记4
路由传参 第一种 router.js { path: '/course/detail/:pk/', name: 'course-detail', component: CourseDetail } 传 ...
- Educational Codeforces Round 81 (Rated for Div. 2) - D. Same GCDs(数学)
题目链接:Same GCDs 题意:给你两个数$a$,$m(1 \leq a < m \leq 10^{10})$,求有多少个$x$满足:$0 \leq x < m$且$gcd(a,m)= ...
- call深入理解
function fn1() { console.log(1); } function fn2() { console.log(2); } fn1.call(fn2); // 1 fn1.call.c ...
- 移动端rem自适应方案
一般设计师给我们的设计稿尺寸都为750*1340 .. 网易,淘宝移动端首页上html元素的font-size 目前就先说一下网易的做法 引入下面这段js,用于计算动态的font-size (func ...
- 使用js制作 下拉选择日期列表 (即日期选择器)
上代码 <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <tit ...
- centsos 7 删除自带jdk安装自定义jdk8
甲骨文官网地址:https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 如何清除自带j ...