hdu 5245 Joyful
来源:互联网 发布:ipad2越狱后必装软件 编辑:程序博客网 时间:2024/06/09 17:02
Problem Description
Sakura has a very magical tool to paint walls. One day, kAc asked Sakura to paint a wall that looks like anM×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 forK times. More specifically, each time for Sakura to use that tool, she just randomly picks two squares from all theM×N squares, with equal probability. Now, kAc wants to know the expected number of squares that will be painted eventually.
However, Sakura is a very naughty girl, so she just randomly uses the tool for
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 integersM,N and K .
It is guaranteed that1≤M,N≤500 ,1≤K≤20 .
For each test case, there is only one line, with three integers
It is guaranteed that
Output
For each test case, output ''Case #t:'' to represent thet -th case, and then output the expected number of squares that will be painted. Round to integers.
Sample Input
23 3 14 4 2
Sample Output
Case #1: 4Case #2: 8HintThe precise answer in the first test case is about 3.56790123.
Source
The 2015 ACM-ICPC China Shanghai Metropolitan Programming Contest
题意:给一个N*M的网格,现在选K轮子矩形,每轮的矩形由随机选取的两个对顶点确定,求最终的被选中过的格子的数目。
分析:我们可以求出格子(i,j)被选中的概率pij,则答案为∑pij*i。
对于每个格子,k次选择相互独立,直接求选中的概率pij比较困难,但是k次未选中概率为pow(qij,k)比较好求,那么pij = 1 - pow(qij,k)。
但是对于其中一轮,格子(i,j)未被选中的qij不好求出,而选中概率比较好求(1-qij) = (1-((n-i)*(n-i)+(i-1)*(i-1)/(n*n)) * (1-((m-j)*(m-j)+(j-1)*(j-1))/(m*m));
题意:给一个N*M的网格,现在选K轮子矩形,每轮的矩形由随机选取的两个对顶点确定,求最终的被选中过的格子的数目。
分析:我们可以求出格子(i,j)被选中的概率pij,则答案为∑pij*i。
对于每个格子,k次选择相互独立,直接求选中的概率pij比较困难,但是k次未选中概率为pow(qij,k)比较好求,那么pij = 1 - pow(qij,k)。
但是对于其中一轮,格子(i,j)未被选中的qij不好求出,而选中概率比较好求(1-qij) = (1-((n-i)*(n-i)+(i-1)*(i-1)/(n*n)) * (1-((m-j)*(m-j)+(j-1)*(j-1))/(m*m));
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<stack>#include<set>#include<cmath>using namespace std;typedef long long LL;int main(){ int i,j,k,m,n,T; int cas = 0; scanf("%d",&T); while(T--) { scanf("%d %d %d",&m,&n,&k); double ans = 0; for(i=1; i<=n; i++) for(j=1; j<=m; j++) { double p = (1.0-(1.0*(n-i)*(n-i)+1.0*(i-1)*(i-1))/(1.0*n*n)) *(1.0-(1.0*(m-j)*(m-j)+1.0*(j-1)*(j-1))/(1.0*m*m)); ans+=1.0-pow(1.0-p, k*1.0); } printf("Case #%d: %.0f\n",++cas,ans); } return 0;}
0 0
- HDU 5245 - Joyful
- hdu 5245 Joyful
- HDU 5245 Joyful
- HDU 5245 Joyful
- HDU 5245 Joyful (期望)
- HDU 5245 Joyful
- HDU 5245 Joyful (概率期望)
- HDU 5245 Joyful (概率题 求期望)
- HDU 5245 Joyful (数学概率求期望)
- HDU 5245 Joyful(概率 期望)
- Hdu 5245 Joyful【滚动数组+概率Dp】
- hdu 5245 joyful 2015acm上海大都会邀请赛
- HDU 5245 joyful( 2015 Shanghai Metropolitan J )
- HDU 5245 Joyful 经典概率题目推公式
- HDOJ 5245 Joyful
- HDU 5245 Joyful (2015年上海大都赛J题,概率)
- HDU 5245 Joyful(概率求期望)——2015年上海邀请赛
- HDU 5345 Joyful(概率题求期望)
- 使用map+函数指针代替switch和if-else的一个例子
- LeetCode 之 Reverse Linked List — C 实现
- Ubuntu 查看和杀死进程
- 1.SpringMVC开发环境搭建
- 对常用的软件开发模型的总结与个人理解_Phoenix-晶
- hdu 5245 Joyful
- 不用+、-、×、÷对两个数求和
- [leetcode] 77.Combinations
- 个人笔记之构造方法
- Android 仿微信对话列表滑动删除效果
- 如何学习PostgreSql sql 语法
- Mike and Frog(CF547A)
- C++ int与string的转化
- 第二届SDN大赛--提高题2