您的位置:首页 > 其它

hdu 5570 balls(期望好题)

2015-11-22 14:59 309 查看
[align=left]Problem Description[/align]

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.


[align=left]Input[/align]

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)


[align=left]Output[/align]

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


[align=left]Sample Input[/align]

2 2
1 1
3 5

2 2
4 5
4 2

2 2
2 4
1 4


[align=left]Sample Output[/align]

3.00
2.96
3.20


[align=left]Source[/align]
BestCoder Round #63 (div.2)

附上中文题目:

#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

;
double p

;
int main()
{
while(scanf("%d%d",&n,&m)==2){
for(int i=0;i<n;i++){
double sum=0;
for(int j=0;j<m;j++){
scanf("%lf",&a[i][j]);
sum+=a[i][j];
}
for(int j=0;j<m;j++){
p[i][j]=a[i][j]*1.0/sum;
}
}
double ans=0;
for(int j=0;j<m;j++){
double sum=0;
for(int i=0;i<n;i++){
ans+=p[i][j]*(1.0-p[i][j]);
}
for(int i=0;i<n;i++){
sum+=p[i][j];
}
ans+=sum*sum;
}
printf("%.2lf\n",ans);
}
return 0;
}


View Code

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: