CF596D.Wilbur and Trees

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Wilbur the pig really wants to be a beaver, so he decided today to pretend he is a beaver and bite at trees to cut them down.

There are nn trees located at various positions on a line. Tree ii is located at position xix_{i} . All the given positions of the trees are distinct.

The trees are equal, i.e. each tree has height hh . Due to the wind, when a tree is cut down, it either falls left with probability pp , or falls right with probability 1p1-p . If a tree hits another tree while falling, that tree will fall in the same direction as the tree that hit it. A tree can hit another tree only if the distance between them is strictly less than hh .

For example, imagine there are 44 trees located at positions 11 , 33 , 55 and 88 , while h=3h=3 and the tree at position 11 falls right. It hits the tree at position 33 and it starts to fall too. In it's turn it hits the tree at position 55 and it also starts to fall. The distance between 88 and 55 is exactly 33 , so the tree at position 88 will not fall.

As long as there are still trees standing, Wilbur will select either the leftmost standing tree with probability 0.50.5 or the rightmost standing tree with probability 0.50.5 . Selected tree is then cut down. If there is only one tree remaining, Wilbur always selects it. As the ground is covered with grass, Wilbur wants to know the expected total length of the ground covered with fallen trees after he cuts them all down because he is concerned about his grass-eating cow friends. Please help Wilbur.

输入格式

The first line of the input contains two integers, nn (1<=n<=2000)(1<=n<=2000) and hh (1<=h<=108)(1<=h<=10^{8}) and a real number pp ( 0<=p<=10<=p<=1 ), given with no more than six decimal places.

The second line of the input contains nn integers, x1,x2,...,xnx_{1},x_{2},...,x_{n} (108<=xi<=108)(-10^{8}<=x_{i}<=10^{8}) in no particular order.

输出格式

Print a single real number — the expected total length of the ground covered by trees when they have all fallen down. Your answer will be considered correct if its absolute or relative error does not exceed 10610^{-6} .

Namely: let's assume that your answer is aa , and the answer of the jury is bb . The checker program will consider your answer correct, if .

输入输出样例

  • 输入#1

    2 2 0.500000
    1 2
    

    输出#1

    3.250000000
    
  • 输入#2

    4 3 0.4
    4 3 1 2
    

    输出#2

    6.631200000
    

说明/提示

Consider the first example, we have 2 trees with height 2.

There are 3 scenarios: 1. Both trees falls left. This can either happen with the right tree falling left first, which has probability (also knocking down the left tree), or the left tree can fall left and then the right tree can fall left, which has probability. Total probability is .

  1. Both trees fall right. This is analogous to (1), so the probability of this happening is .

  2. The left tree fall left and the right tree falls right. This is the only remaining scenario so it must have probability.

Cases 1 and 2 lead to a total of 3 units of ground covered, while case 3 leads to a total of 4 units of ground covered. Thus, the expected value is .

首页