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 answerwill 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 100962E: Elvis Presley 题解
- Codeforces Gym 100962 J. Jimi Hendrix
- Codeforces GYM 100962J: Jimi Hendrix 题解
- CodeForces Gym 100735C BFS
- Codeforces Gym 100531D Digits 暴力
- codeforces gym 100463I Yawner
- codeforces Gym 100187 B. A Lot of Joy (期望)
- Codeforces Gym 100269D Dwarf Tower spfa
- Codeforces gym 101350F 想法
- Codeforces Gym 100199 B Reactor Cooling
- Codeforces gym 100685 F. Flood bfs
- CodeForces Gym 101190简要题解
- Codeforces Gym 101498K. Two Subarrays
- Codeforces Gym 100342E Problem E. Minima 暴力
- 【最短路】BAPC2014 B Button Bashing (Codeforces GYM 100526)
- Codeforces Gym 100379I Move the queen to the corner! 威佐夫博弈变形 + 高精度
- Codeforces Gym 100338C Important Roads 最短路+Tarjan找桥
- Codeforces Gym 100733I The Cool Monkeys 拆点+最大流
- Codeforces Gym 100202C Holidays
- Codeforces Gym 100341I Hungry Queen 2 Set水题