Codeforces Gym 100962 H. Hans Zimmer
来源:互联网 发布:手机计步器软件排行 编辑:程序博客网 时间:2024/04/30 20:58
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
the expected value of
Input
The only line of input contains three space-separated integers w, h and n (
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
error no more that
题意
对给定的
分析
期望公式:
膜拜队友大神,给出期望公式 :haha:
T_T 然而此题不止一个坑点。显然计算 n=1000000
时,各种数据类型都已经无法表示。但套用 log
和 exp
的策略可解决这个问题。因此,对期望公式加以转换:
貌似非常卡精度,全部用
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 100962 H. Hans Zimmer
- Hans Zimmer和他的《The Rock》
- codeforces GYM 100792H
- 【Codeforces Gym】100162 H Temperature
- Codeforces Gym 100623H Problem H. Holes
- Codeforces Gym 100342H Hard Test 构造
- CodeForces Gym 100989H Queue (A)
- [DP] Codeforces Gym 101002 H. Jewel Thief
- Codeforces Gym 101234H Split Game
- ICPCCamp 2016 Day 7 - Moscow SU Trinity Contest(Hans Zimmer-期望)
- Codeforces Gym 100345H Settling the Universe Up Bitset+倒推
- [Codeforces Gym]100162 H - Temperature 状态压缩dp
- codeforces Gym 100500Problem H. ICPC Quest 简单DP
- Codeforces Gym 100733H Designation in the Mafia flyod
- Codeforces Gym 101164 H. Pub crawl (凸包)
- [DP 决策单调性] Codeforces Gym 101002H .Jewel Thief
- Codeforces Gym 100015H Hidden Code(暴力)
- 【Codeforces Gym
- Linux虚拟机环境搭建所遇到的问题
- C++ 长整型数据的输出
- 网页安全测试
- AXI4、AXI4-Lite、AXI-Stream总线协议的简单认识
- 如何提取iOS App素材
- Codeforces Gym 100962 H. Hans Zimmer
- Leetcode 51. N-Queens
- [USACO1.3]混合牛奶 Mixing Milk
- C Primer Plus 知识点整理(一)
- Codeforces Round #397 E. Tree Fold(bfs,想法题,好题)
- 排队接水
- 六角填数(DFS)
- Easy单例模式
- 欢迎使用CSDN-markdown编辑器