# HDU 5245 Joyful

4126人阅读 评论(0)

Joyful

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 781 Accepted Submission(s): 339

Problem Description
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, y-th column. Once Sakura has determined two squares (x1,y1) and (x2,y2), she can use the magical tool to paint all the squares in the sub-matrix which has the given two squares as corners.

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 M×N squares, with equal probability. Now, kAc wants to know the expected number of squares that will be painted eventually.

Input
The first line contains an integer T(T≤100), denoting the number of test cases.

For each test case, there is only one line, with three integers M,N and K.
It is guaranteed that 1≤M,N≤500, 1≤K≤20.

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

Hint

Source
The 2015 ACM-ICPC China Shanghai Metropolitan Programming Contest

My Code：

#include <iostream>
#include <cstdio>
using namespace std;
typedef long long LL;
int main()
{
int T;
cin>>T;
for(int cas=1; cas<=T; cas++)
{
LL m, n, k;
cin>>m>>n>>k;
LL tot = (m*n) * (m*n);
double ret = 0;
for(LL i=1; i<=m; i++)
{
for(LL j=1; j<=n; j++)
{
LL up = ((i-1)*n) * ((i-1)*n);
LL down = ((m-i)*n) * ((m-i)*n);
LL left = ((j-1)*m) * ((j-1)*m);
LL right = ((n-j)*m) * ((n-j)*m);
LL leftup = ((i-1)*(j-1)) * ((i-1)*(j-1));
LL rightup = ((n-j)*(i-1)) * ((n-j)*(i-1));
LL leftdown = ((j-1)*(m-i)) * ((j-1)*(m-i));
LL rightdown = ((m-i)*(n-j)) * ((m-i)*(n-j));
LL ans = up + down + left + right- leftup - rightup - leftdown - rightdown;
///cout<<ans<<endl;
double tp = 1.0;
double p = 1.0*ans/tot;
for(int ii=0; ii<k; ii++)
tp *= p;
ret += 1.0-tp;
}
}
printf("Case #%d: %lld\n",cas,(LL)(ret+0.5));
}
return 0;
}
0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：508387次
• 积分：11338
• 等级：
• 排名：第1597名
• 原创：639篇
• 转载：5篇
• 译文：0篇
• 评论：93条
博客专栏
 计算机专业的相关课程知识 文章：24篇 阅读：31433
 ACM_组合数学 文章：27篇 阅读：31442
 ITAK的ACM之路 文章：295篇 阅读：331078
阅读排行
喜欢的Music
友情推荐