HDU 5245 Joyful(概率求期望)——2015年上海邀请赛
Posted ITAK
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU 5245 Joyful(概率求期望)——2015年上海邀请赛相关的知识,希望对你有一定的参考价值。
Sakura has a very magical tool to paint walls. One day, kAc asked Sakura to paint a wall that looks like an M×N matrix. The wall has M×N squares in all. In the whole problem we denotes (x,y) to be the square at the x -th row,However, Sakura is a very naughty girl, so she just randomly uses the tool for K times. More specifically, each time for Sakura to use that tool, she just randomly picks two squares from all the
Input The first line contains an integer T (
For each test case, there is only one line, with three integers M,N and K .
It is guaranteed that
Output For each test case, output ”Case #t:” to represent the t -th case, and then output the expected number of squares that will be painted. Round to integers.
Sample Input
2 3 3 1 4 4 2
Sample Output
Case #1: 4 Case #2: 8 HintThe precise answer in the first test case is about 3.56790123.
题目大意
给定一个
解题思路
就是对于每一个格子,求其
然而对于每一个格子来说,求
k
次之后被染色的概率不好求,我们可以求
左部分:
(j−1)∗n
右部分:
(m−j)∗n
上部分:
(i−1)∗m
下部分:
(n−i)∗m
再减去重复的部分:
左上:
(i−1)∗(j−1)
右上:
(i−1)∗(m−j)
左下:
(n−i)∗(j−1)
左下:
(n−i)∗(m−j)
所以我们得到总的没有被涂色的面积为
tmp
,涂色的面积就是
1−tmpn∗m∗n∗mk
代码
#include <iostream>
#include <string.h>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <map>
using namespace std;
typedef long long LL;
const int MAXN = 1e6+5;
const double PI = acos(-1);
const double eps = 1e-8;
const LL MOD = 1e9+7;
int main()
//freopen("C:/Users/yaonie/Desktop/in.txt", "r", stdin);
//freopen("C:/Users/yaonie/Desktop/out.txt", "w", stdout);
int T; scanf("%d",&T);
for(int cas=1; cas<=T; cas++)
LL n, m, k; scanf("%lld%lld%lld",&n,&m,&k);
double ans = 0;
LL t = n*n*m*m;
for(LL i=1; i<=n; i++)
for(LL j=1; j<=m; j++)
LL tmp = (j-1)*(j-1)*n*n-(i-1)*(i-1)*(j-1)*(j-1);
tmp += ((m-j)*(m-j)*n*n-(i-1)*(i-1)*(m-j)*(m-j));
tmp += ((i-1)*(i-1)*m*m-(n-i)*(n-i)*(j-1)*(j-1));
tmp += ((n-i)*(n-i)*m*m-(n-i)*(n-i)*(m-j)*(m-j));
double sum = 1;
double a = 1.0*tmp/t;
LL b = k;
while(b)
if(b&1) sum=sum*a;
b>>=1;
a=a*a;
ans += 1-sum;
printf("Case #%d: %.0f\\n",cas, ans);
return 0;
以上是关于HDU 5245 Joyful(概率求期望)——2015年上海邀请赛的主要内容,如果未能解决你的问题,请参考以下文章