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. SpringMVC——注解的使用与结果跳转方式

    1.项目结构 2.源代码 package com.zhengbin.controller; import java.io.IOException; import javax.servlet.Servl ...

  2. printk 驱动调试

    驱动的调试,printk()添加调试信息 printk相当于printf的孪生姐妹,它们一个运行在用户态,另一个则在内核态. 需要包含<linux/device.h>或者<linux ...

  3. JS 代码编一个倒时器

    有时候在生活中,你需要一个JavaScript倒计时时钟,而不是一个末日装置设备.不管你是否有一次约会,销售.促销.或者游戏,你可以受益于使用原生JavaScript构建一个时钟,而不是拿到一个现成的 ...

  4. A标记点击后去掉虚线

    没加时,谷歌无虚线,但ie有虚线. 加上这句,所有的a标签点击都没有虚线了. a {outline: none;} a:active {star:expression_r(this.onFocus=t ...

  5. awk简单使用『摘.非原创』

    1 awk简介 awk是一种编程语言,用于在linux/unix下对文本和数据进行处理.数据可以来自标准输入.一个或多个文件,或其它命令的输出.它支持用户自定义函数和动态正则表达式等先进功能,是lin ...

  6. IOS Swizzle(hook)

    /////////////////////////////////////////////////////////////////////////////////////////////////// ...

  7. Tableau学习笔记之二

    2张图片解析下Tableau 9.0界面的功能 1.数据加载界面: 2.数据分析界面:

  8. Android引用百度定位API第三方组件后导致其它.so文件无法正常加载的问题

    查看当前调试设备CPU架构的方法: adb.exe shell getprop ro.product.cpu.abi  (一般返回值为:armeabi-v7a) adb.exe shell getpr ...

  9. 【原】Storm序列化

    5. Storm高级篇 序列化 Dynamic typing Custom serialization Java serialization Component-specific serializat ...

  10. ASP.NET MVC中使用ASP.NET AJAX异步访问WebService

    使用过ASP.NET AJAX的朋友都知道,怎么通过ASP.NET AJAX在客户端访问WebService,其实在ASP.NET MVC中使用ASP.NET AJAX异步访问WebService 也 ...