关闭

HDU 5245 Joyful

标签: 概率DP
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
The precise answer in the first test case is about 3.56790123.

Source
The 2015 ACM-ICPC China Shanghai Metropolitan Programming Contest

题目大意:
就是有一个 m*n 的矩阵方格,然后你每次取两个方格,分别是(x1,y1)和(x2,y2);然后就是每次覆盖一个子矩阵是以(x1,y1)和(x2,y2)为对角线构成的矩阵,让你求的就是你进行 k 次之后得到的方格数的期望。

解题思路:
其实这个题,画一下就行了而且非常清楚,我也不会画,我就用语言描述啦,我们先求一下总的方案数,第一个方格是m*n,第二个方格还是m*n,那么总的方案数就是 m^2*n^2,假设我们选的(i, j)点就是没有被覆盖的点,那么我们选的那两个方格肯定是 i行上面的和下面的 j列左面的和右面的,但是我们重复了那4个角(其实也不能叫角,应该叫子矩阵),所以我们要减去那四个角的矩阵,假设结果是ans,那么概率显然就是 p = ans/(m^2*n^2)然后我们取了k次之后就是p^k,那么被覆盖的概率就是 1-p^k,然后我们进行的就是 两个循环 for(i: 1-m),for(j: i-n),那么每次都对1-p^k进行累加得到的就是期望,注意的就是m^2*n^2会爆int,
最后的结果是四舍五入的,有一个小窍门(四舍五入的时候加上0.5就行了)
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网站的观点或立场

HDU 5245 Joyful(概率 期望)

Joyful Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total S...
  • u014665013
  • u014665013
  • 2017-04-30 20:22
  • 340

HDU 5245 Joyful (数学概率求期望)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5245题意:给定一个n行m列的方阵,每次选2个点(x1,y1),(x2,y2),由这两个点为左上角和右下...
  • neau2014
  • neau2014
  • 2015-09-05 15:11
  • 248

Hdu 5245 Joyful【滚动数组+概率Dp】

Joyful Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Sub...
  • mengxiang000000
  • mengxiang000000
  • 2017-07-30 16:11
  • 137

HDU 5245 Joyful(概率求期望)——2015年上海邀请赛

传送门Sakura has a very magical tool to paint walls. One day, kAc asked Sakura to paint a wall that loo...
  • qingshui23
  • qingshui23
  • 2017-10-26 17:32
  • 595

HDU 5245 Joyful (2015年上海大都赛J题,概率)

HDU 5245 Joyful (2015年上海大都赛J题,概率)
  • u013790563
  • u013790563
  • 2015-05-28 09:11
  • 1168

HDU 5245 Joyful 经典概率题目推公式

公式题 别人的很详细的推理过程,复制过来做笔记。 题意大致是:进行K次染色,每次染色会随机选取一个以(x1,y1),(x2,y2)为一组对角的子矩阵进行染色,求K次染色后染色面积的期望值(四舍五入...
  • became_a_wolf
  • became_a_wolf
  • 2016-05-11 17:59
  • 133

HDU 5245 期望概率

Joyful Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total S...
  • DlPF_C
  • DlPF_C
  • 2017-11-17 20:34
  • 35

rfc5245--概要翻译1

前言: rfc5245介绍了 NAT下p2p的解决框架ICE(Interactive Connectivity Establishment) 此文档取代了过时的rfc4091, rfc4092  r...
  • spivic
  • spivic
  • 2014-03-11 14:19
  • 1685

HDU 5245 Joyful(线段树、查询区间和及修改区间每个数为数的平方)

题目链接: HDU 5245 Joyful 题意: 查询区间和及修改查询区间,将每个数都变为数的平方。模数是92233720347072921609223372034707292160。#inc...
  • Ramay7
  • Ramay7
  • 2016-04-29 01:12
  • 376

HDU 5345 Joyful(概率题求期望)

D - Joyful Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u S...
  • qq_33328072
  • qq_33328072
  • 2016-05-24 10:19
  • 182
    个人资料
    • 访问:508387次
    • 积分:11338
    • 等级:
    • 排名:第1597名
    • 原创:639篇
    • 转载:5篇
    • 译文:0篇
    • 评论:93条
    博客专栏