您的位置:首页 > 其它

Codeforces Gym 100962 H. Hans Zimmer

2017-02-19 11:30 344 查看

Description

Hans wants to become a glass carver (a person who creates beautiful artwork by cutting the glass).

He already has a rectangular piece of glass of size w  h millimeters, a diamond glass cutter and

lots of enthusiasm. What he lacks is understanding of what to carve and how.

In order not to waste time, he decided to practice the technique of carving. To do this, he makes

vertical and horizontal cuts through the entire sheet. This process results in making smaller

rectangular fragments of glass. Hans does not move the newly made glass fragments. In particular,

a cut divides each fragment of glass that it goes through into smaller fragments.

Hans doesn’t know how to make a great artwork, so he performs random cuts as follows. First,

he tosses a fair coin to determine if he is going to cut the glass vertically or horizontally (that is,

the probability of choosing each direction is 50%). After that, he chooses a uniformly distributed

random real point on the corresponding side of the rectangle, and makes a cut through that point.All n random points and all n coin tosses are mutually independent.

Hans is going to perform exactly n cuts. What he is interested in, is the fragment with the smallest

area that is formed after he makes all cuts. Denote its area as ξ. Your task is to calculate E[ξ],

the expected value of ξ.

Input

The only line of input contains three space-separated integers w, h and n (1≤w,h≤103,1≤n≤106), the size of the piece of glass and the number of cuts Hans is going to perform.

Output

Output the expected area of the smallest fragment formed after performing all cuts. Your answer

will be considered correct if its relative error is no more than 10−4 (note that having absolute

error no more that 10−4 is not enough).

题意

对给定的 h×w 的矩形在等概率的情况下任意横切或纵切 n 下,将矩形分为若干块,其中计最小一块的面积为 ξ ,试求最小面积的期望 E[ξ] 。

分析

期望公式:

E[ξ]=Σni=0Cin2n(i+1)2(n−i+1)2

​膜拜队友大神,给出期望公式 :haha:

T_T 然而此题不止一个坑点。显然计算 2n 当
n=1000000
时,各种数据类型都已经无法表示。但套用
log
exp
的策略可解决这个问题。因此,对期望公式加以转换:

E[ξ]=Σni=0elnCin−(nln2+2ln(i+1)+2ln(n−i+1))

貌似非常卡精度,全部用
long double


代码

#include<bits/stdc++.h>
using namespace std;
int main()
{
int w, h, n;
scanf("%d %d %d",&w,&h,&n);
long double log_pow2 = log(2.0) * n;
long double c_i_n = 0.0;
long double ans = 0.0;
for(int i=0;i<=n;i++)
{
if(i)   c_i_n += log((n-i+1) * 1.0 / i);
long double denominator = 2*log(i+1.0) + 2*log(n-i+1.0) + log_pow2;
ans += exp( c_i_n - denominator );
}
cout<<ans*h*w<<endl;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  codeforces Gym