hdu 5245__Joyful
来源:互联网 发布:软件项目建议书范文 编辑:程序博客网 时间:2024/06/06 03:59
Joyful
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 515 Accepted Submission(s): 224
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 forK 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.
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 the t -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次染色,每次选取两个点(x1,y1),(x2,y2)作为染色矩形的对角顶点。求k次染色后染色面积的期望值。
题解参考了这位大牛的博客。代码如下。
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespace std;int main(){ int T,n,m,k,cas=1; scanf("%d",&T); while(T--) { scanf("%d%d%d",&n,&m,&k); double ans=0; for(double i=1;i<=n;i++) { for(double j=1;j<=m;j++) { double p=0; p+=(i-1)*(j-1)*(m-j+1)*(n-i+1);//1 p+=(i-1)*(n-i+1)*m;//2 p+=(i-1)*(m-j)*(n-i+1)*j;//3 p+=(j-1)*(m-j+1)*n;//4 p+=n*m;//5 p+=(m-j)*n*j;//6 p+=(n-i)*(j-1)*i*(m-j+1);//7 p+=(n-i)*i*m;//8 p+=(n-i)*(m-j)*i*j;//9 p=p/n/m/n/m; ans+=1-pow(1-p,k);//k次染色操作被染色的概率 } } printf("Case #%d: %d\n",cas++,int(ans+0.5)); } return 0;}
0 0
- hdu 5245__Joyful
- HDU 5245
- HDU 5245 - Joyful
- hdu 5245 Joyful
- HDU 5245 Joyful
- HDU 5245 Joyful
- HDU 5245 Joyful (期望)
- HDU 5245 Joyful
- HDU 5245 期望概率
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- jieba中文分词源码分析(四)
- INSTALL_FAILED_SHARED_USER_INCOMPATIBLE的问题
- Vitamio 尺寸固定,自定义一个MediaController依附在VideoView
- activity
- 百度天气api初体验
- hdu 5245__Joyful
- Java学习笔记20150907
- Effective C++——条款27(第5章)
- iOS中Keychain保存用户名和密码
- How can I become data scientist?FAQ
- HUST 1010The Minimum Length
- HDU 5430-Reflect(欧拉函数求圆内反射方法数)
- VS2010/MFC编程入门之十一中(对话框:模拟对话及其弹出过程)学习时的一个注意点
- SpringMVC—接收请求参数和页面传参