balls

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=5570

Description

There are n balls with m colors. The possibility of that the color of the i-th ball is color j is ai,jai,1+ai,2+...+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.

Input

Several test cases(about 5)

For each cases, first come 2 integers, n,m(1≤n≤1000,1≤m≤1000)

Then follows n lines with m numbers ai,j(1≤ai≤100)

Output

For each cases, please output the answer with two decimal places.

Sample Input

2 2
1 1
3 5

2 2
4 5
4 2

2 2
2 4
1 4

Sample Output

3.00
2.96
3.20

HINT

题意

题解:

贡献为x^2,其实就是问你期望的对数有多少个

假设p[i][j]表示第一个位置出现颜色为j的的概率是多少,那么我们可以推出来该颜色期望的对数的公式是

ans = p[i][1] + p[i][2]+ ... + p[i][m] + p[i][1]*p[i][2] + p[i][1]*p[i][3] + .... + p[i][2]*p[i][1]+ ... + p[i][m]*p[i][m-1]

然后化简,就可以得到ans = sigma(p[i][k]) + sigma(p[i][k]) * sigma(p[i][k]) - sigma(p[i][k]*p[i][k])

就可以On来处理答案啦~

代码:

#include<iostream>
#include<stdio.h>
using namespace std; int n,m;
double a[][];
double s[];
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
for(int i=;i<=n;i++)
{
s[i]=;
for(int j=;j<=m;j++)
{
scanf("%lf",&a[i][j]);
s[i]+=a[i][j];
}
}
double ans = ;
for(int j=;j<=m;j++)
{
double s1 = ;
double s2 = ;
for(int i=;i<=n;i++)
{
double p = a[i][j]/s[i];
s1+=p;
s2+=p*p;
}
ans += s1 + s1*s1 - s2;
}
printf("%.2f\n",ans);
}
}

HDU 5570 balls 期望 数学的更多相关文章

  1. hdu 5570 balls(期望好题)

    Problem Description There are n balls with m colors. The possibility of that the color of the i-th b ...

  2. HDU 4611 Balls Rearrangement 数学

    Balls Rearrangement 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=4611 Description Bob has N balls ...

  3. hdu 4710 Balls Rearrangement (数学思维)

    意甲冠军:那是,  从数0-n小球进入相应的i%a箱号.然后买一个新的盒子. 今天的总合伙人b一个盒子,Bob试图把球i%b箱号. 求复位的最小成本. 每次移动的花费为y - x ,即移动前后盒子编号 ...

  4. HDU 5810 Balls and Boxes(盒子与球)

     Balls and Boxes(盒子与球) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/O ...

  5. HDU 5570:balls 期望。。。。。。。。。。。。。。。

    balls  Accepts: 19  Submissions: 55  Time Limit: 6000/3000 MS (Java/Others)  Memory Limit: 65536/655 ...

  6. HDU 5810 Balls and Boxes 数学

    Balls and Boxes 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5810 Description Mr. Chopsticks is i ...

  7. hdu 3232 Crossing Rivers(期望 + 数学推导 + 分类讨论,水题不水)

    Problem Description   You live in a village but work in another village. You decided to follow the s ...

  8. HDU 4465 Candy (数学期望)

    题意:有两个盒子各有n个糖(n<=2*105),每天随机选1个(概率分别为p,1-p),然后吃掉一颗糖.直到有一天打开盒子一看,这个盒子没有糖了.输入n,p,求此时另一个盒子里糖的个数的数学期望 ...

  9. HDU 4336 Card Collector 数学期望(容斥原理)

    题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=4336 题意简单,直接用容斥原理即可 AC代码: #include <iostream> ...

随机推荐

  1. plsql developer 使用技巧

    plsql developer 使用技巧 Oracle数据库相信已成为很多企业构建自身关键业务的重要后台支撑,也是众多开发人员常常采用的后台.但Oracle自己提供的一套客户端工具不是很好用,极大的影 ...

  2. Xcode中使用svn时,报证书验证错误Error validating server certificate for

    转:http://blog.csdn.net/yhawaii/article/details/7511141 今天使用Xcode自带的svn客户端时,总是连接不上服务器,报如下错误: Error va ...

  3. GreenDao官方文档翻译(上)

    笔记摘要: 上一篇博客简单介绍了SQLite和GreenDao的比较,后来说要详细介绍下GreenDao的使用,这里就贴出本人自己根据官网的文档进行翻译的文章,这里将所有的文档分成上下两部分翻译,只为 ...

  4. CPC23-4 K.喵喵的神·数

    题意:给出整数T,P,求c(T,P) mod P. 解法:用卢卡斯定理. 卢卡斯定理:解决c(n,m) mod p问题.Lucas(n,m,p)=c(n%p,m%p)*Lucas(n/p,m/p,p) ...

  5. Inxi:获取Linux系统和硬件信息的神器

    导读 在这篇文章里,我们将看到如何使用inxi来获取这些详情信息.在论坛技术支持中,它可以作为调试工具,迅速确定用户的系统配置和硬件信息. Inxi是一个可以获取完整的系统和硬件详情信息的命令行工具, ...

  6. Islands and Bridges(POJ 2288状压dp)

    题意:给你一个图和每个点的价值,边权值为连接两点权值的积,走哈密顿通路,若到达的点和上上个点相连则价值加三点乘积,求哈密顿通路的最大价值,和最大价值哈密顿通路的条数. 分析:开始看这个题很吓人,但想想 ...

  7. <转>Python 多线程的单cpu与cpu上的多线程的区别

    你对Python 多线程有所了解的话.那么你对python 多线程在单cpu意义上的多线程与多cpu上的多线程有着本质的区别,如果你对Python 多线程的相关知识想有更多的了解,你就可以浏览我们的文 ...

  8. C++ 出现bug :二位数组的操作运算,求非对角线的元素的和

    编写一个通用程序,求出二位数组(行数和列数必须相等)的非对角线的元素之和,试建立类MATRIX完成上述功能 #include<iostream> using namespace std; ...

  9. 【转载】cocos2d-x教程 Mac系统下搭建Lua的编码环境

    原文链接:http://blog.csdn.net/u012945598/article/details/17168831   在使用Lua写脚本的时候大家都会因为没有代码提示导致敲代码的效率有所下降 ...

  10. springmvc里面的中文乱码问题

    如果是以get方法提交的表单,则可以在comcat服务器的server.xml文件里面设置 <Connector connectionTimeout="20000" port ...