hdu 5570 balls(期望好题)
There are n balls with m colors. The possibility of that the color of the i-th ball is color j is ai,jai,+ai,+...+ai,m. If the number of balls with the j-th is x, then you should pay x2 as the cost. Please calculate the expectation of the cost.
Several test cases(about ) For each cases, first come integers, n,m(≤n≤,≤m≤) Then follows n lines with m numbers ai,j(≤ai≤)
For each cases, please output the answer with two decimal places.
3.00
2.96
3.20
附上中文题目:
附上官方题解:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<stdlib.h>
#include <stack>
using namespace std;
#define PI acos(-1.0)
#define max(a,b) (a) > (b) ? (a) : (b)
#define min(a,b) (a) < (b) ? (a) : (b)
#define ll long long
#define eps 1e-10
#define MOD 1000000007
#define N 1006
#define inf 1e12
int n,m;
double a[N][N];
double p[N][N];
int main()
{
while(scanf("%d%d",&n,&m)==){
for(int i=;i<n;i++){
double sum=;
for(int j=;j<m;j++){
scanf("%lf",&a[i][j]);
sum+=a[i][j];
}
for(int j=;j<m;j++){
p[i][j]=a[i][j]*1.0/sum;
}
}
double ans=;
for(int j=;j<m;j++){
double sum=;
for(int i=;i<n;i++){
ans+=p[i][j]*(1.0-p[i][j]);
}
for(int i=;i<n;i++){
sum+=p[i][j];
}
ans+=sum*sum;
}
printf("%.2lf\n",ans);
}
return ;
}
{3BKPSJUAOIDU@)[CH.png)
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 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 5570:balls 期望。。。。。。。。。。。。。。。
balls Accepts: 19 Submissions: 55 Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/655 ...
- UVa 12230 && HDU 3232 Crossing Rivers (数学期望水题)
题意:你要从A到B去上班,然而这中间有n条河,距离为d.给定这n条河离A的距离p,长度L,和船的移动速度v,求从A到B的时间的数学期望. 并且假设出门前每条船的位置是随机的,如果不是在端点,方向也是不 ...
- hdu 5245 Joyful(期望的计算,好题)
Problem Description Sakura has a very magical tool to paint walls. One day, kAc asked Sakura to pain ...
- HDU 4611 Balls Rearrangement (数学-思维逻辑题)
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4611 题意:给你一个N.A.B,要你求 AC代码: #include <iostream> ...
- HDU 4611 Balls Rearrangement(2013多校2 1001题)
Balls Rearrangement Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Othe ...
- HDU 5245 上海大都会 J题 (概率期望)
这道题的概率可以单独考虑每个格子对期望的贡献值.因为其实每个格子是否被选都可以认为是独立的,单独一个格子贡献的期望为1*(该格子K次被选的概率),所以答案其实就是每个格子K次被选中的概率之和. #in ...
随机推荐
- Windows多线程同步系列之一-----互斥对象
多线程同步之互斥对象 作者:vpoet mail:vpoet_sir@163.com 对卖票问题进行线程间同步,本文将在上文的基础上,使用互斥对象对线程进行同步. 首先看看windows API ...
- POJ 2263 Heavy Cargo(Floyd + map)
Heavy Cargo Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3768 Accepted: 2013 Descr ...
- IOS使用C#预处理命令,多种SDK共存
当我们使用Unity接 91,XY助手等等SDK时候. 我们需要使用[DllImport("__Internal")] 来声明一个C++的方法调用. 不同的SDK总会有不同的方法. ...
- 棋盘覆盖(大数阶乘,大数相除 + java)
棋盘覆盖 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 在一个2k×2k(1<=k<=100)的棋盘中恰有一方格被覆盖,如图1(k=2时),现用一缺角的 ...
- activity之栈管理
在android中.一个activity组件能够激活还有一个activity组件:本程序activity和其他程序的activity. 若新的被激活的activity组件属于还有一个应用程序, ...
- NET基础课--XML基础
id level是属性,title为子节点 接下来操作子节点 比较xml的处理方式: 1和3适合数据量小的时候.
- JavaScript sort()方法比较器
当我们想把一个由数字组成的数组进行简单的排序时,可能会想到sort()方法: var arr = [2 , 3, -1, -107, -14, 1]; console.log(arr.sort()) ...
- 查看并设置oracle并发连接数
1.Sql代码1.select count(*) from v$process select count(*) from v$process --当前的数据库连接数2.Sql代码1.select v ...
- JQ动画 show hide
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- achartengine 实现平行线 动态数据 x轴动态移动
achartengine做平行线的时候经常会遇到: java.lang.IndexOutOfBoundsException: Invalid index 1, size is 1 at java.ut ...