HDU 5245 Joyful (期望)

题意:进行K次染色,每次染色会随机选取一个以(x1,y1),(x2,y2)为一组对角的子矩阵进行染色,求K次染色后染色面积的期望值(四舍五入)。

析:我们可以先求出每个格子的期望,然后再加起来即可。我们可以把格子进行划分,然后再求概率。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e16;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
  return r >= 0 && r < n && c >= 0 && c < m;
}

int main(){
  int T;  cin >> T;
  for(int kase = 1; kase <= T; ++kase){
    int k;
    cin >> n >> m >> k;
    double ans = 0.0;
    for(int i = 1; i <= n; ++i)
      for(int j = 1; j <= m; ++j){
        double p = m * n;
        p += 1.0 * (i-1) * (j-1) * (n-i+1) * (m-j+1);
        p += 1.0 * (i-1) * (m-j) * (n-i+1) * j;
        p += 1.0 * (j-1) * (n-i) * (m-j+1) * i;
        p += 1.0 * (n-i) * (m-j) * i * j;
        p += 1.0 * (i-1) * m * (n-i+1);
        p += 1.0 * (m-j) * n * j;
        p += 1.0 * (n-i) * m * i;
        p += 1.0 * (j-1) * n * (m-j+1);
        p = p / (1.0*n*n*m*m);
        ans += 1.0 - (pow(1.0-p, k));
      }
    printf("Case #%d: %.f\n", kase, ans);
  }
  return 0;
}

  

时间: 2024-07-29 21:57:27

HDU 5245 Joyful (期望)的相关文章

hdu 5245 Joyful(期望的计算,好题)

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

HDU 5245 Joyful (概率题 求期望)

Joyful Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 478    Accepted Submission(s): 209 Problem Description Sakura has a very magical tool to paint walls. One day, kAc asked Sakura to paint a

hdu 5245 Joyful(期望)

Joyful Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1243    Accepted Submission(s): 546 Problem Description Sakura has a very magical tool to paint walls. One day, kAc asked Sakura to paint a

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

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5245 题意: 给定一个n*m的矩形,由n*m个格子组成,我们可以选k次,每次可以选择的两个格子 这两个格子作为矩形的对角线可以确定一个矩形,这个矩形里的所有小格子都会被覆 盖,求k次后,被覆盖的格子的个数的期望. 分析: 棋盘被覆盖的格子数的期望 = 每个格子被覆盖的概率的和. 每次选择的方案有n*m*n*m种. 格子坐标为(i,j)被覆盖的方案数为: tot = 2*(2*(i*j*(n-i+1)

HDU 5245 Joyful

传送门 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 w

J - Joyful HDU - 5245 (概率)

题目链接: J - Joyful  HDU - 5245 题目大意:给你一个n*m的矩阵,然后你有k次涂色机会,然后每一次可以选定当前矩阵的一个子矩阵染色,问你这k次用完之后颜色个数的期望. 具体思路:颜色个数的期望等于每一个方块单独的期望加起来,就是总的期望. 对于当前的方块的期望,我们先计算这个方块不会出现的概率,就是当前的(x,y),先计算出当前的两个点在他周围四整块的出现的概率,但是这样四个角会重复计算,再去掉就好了. AC代码: 1 #include<bits/stdc++.h> 2

hdu 4586 (概率+期望)

http://acm.hdu.edu.cn/showproblem.php?pid=4586 大致题意:有一个骰子有n个面,掷到每一个面的概率是相等的,每一个面上都有相应的钱数.其中当你掷到m个面之一时,你有多掷一次的机会.问最后所得钱数的期望. 思路:设投掷第一次的期望是p,那么第二次的期望是m/n*p,第三次的期望是 (m/n)^2*p......第N次的期望是(m/n)^(N-1)*p. 那么这些期望之和便是答案.之前也是想到这,但不知道如何处理无限的情况.当时脑卡了,这不是赤裸裸的等比数

HDU 5345 Joyful(概率题求期望)

D - Joyful Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Description Sakura has a very magical tool to paint walls. One day, kAc asked Sakura to paint a wall that looks like an $M \times N$ matrix. The wal

HDU 5245 上海大都会 J题 (概率期望)

这道题的概率可以单独考虑每个格子对期望的贡献值.因为其实每个格子是否被选都可以认为是独立的,单独一个格子贡献的期望为1*(该格子K次被选的概率),所以答案其实就是每个格子K次被选中的概率之和. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #define LL long long using namespace std; int main(){ LL