CF335E.Counting Skyscrapers

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

A number of skyscrapers have been built in a line. The number of skyscrapers was chosen uniformly at random between 22 and 314!314! (314 factorial, a very large number). The height of each skyscraper was chosen randomly and independently, with height ii having probability 2i2^{-i} for all positive integers ii . The floors of a skyscraper with height ii are numbered 00 through i1i-1 .

To speed up transit times, a number of zip lines were installed between skyscrapers. Specifically, there is a zip line connecting the ii -th floor of one skyscraper with the ii -th floor of another skyscraper if and only if there are no skyscrapers between them that have an ii -th floor.

Alice and Bob decide to count the number of skyscrapers.

Alice is thorough, and wants to know exactly how many skyscrapers there are. She begins at the leftmost skyscraper, with a counter at 1. She then moves to the right, one skyscraper at a time, adding 1 to her counter each time she moves. She continues until she reaches the rightmost skyscraper.

Bob is impatient, and wants to finish as fast as possible. He begins at the leftmost skyscraper, with a counter at 1. He moves from building to building using zip lines. At each stage Bob uses the highest available zip line to the right, but ignores floors with a height greater than hh due to fear of heights. When Bob uses a zip line, he travels too fast to count how many skyscrapers he passed. Instead, he just adds 2i2^{i} to his counter, where ii is the number of the floor he's currently on. He continues until he reaches the rightmost skyscraper.

Consider the following example. There are 66 buildings, with heights 11 , 44 , 33 , 44 , 11 , 22 from left to right, and h=2h=2 . Alice begins with her counter at 11 and then adds 11 five times for a result of 66 . Bob begins with his counter at 11 , then he adds 11 , 44 , 44 , and 22 , in order, for a result of 1212 . Note that Bob ignores the highest zip line because of his fear of heights ( h=2h=2 ).

Bob's counter is at the top of the image, and Alice's counter at the bottom. All zip lines are shown. Bob's path is shown by the green dashed line and Alice's by the pink dashed line. The floors of the skyscrapers are numbered, and the zip lines Bob uses are marked with the amount he adds to his counter.

When Alice and Bob reach the right-most skyscraper, they compare counters. You will be given either the value of Alice's counter or the value of Bob's counter, and must compute the expected value of the other's counter.

输入格式

The first line of input will be a name, either string "Alice" or "Bob". The second line of input contains two integers nn and hh ( 2<=n<=300002<=n<=30000 , 0<=h<=300<=h<=30 ). If the name is "Alice", then nn represents the value of Alice's counter when she reaches the rightmost skyscraper, otherwise nn represents the value of Bob's counter when he reaches the rightmost skyscraper; hh represents the highest floor number Bob is willing to use.

输出格式

Output a single real value giving the expected value of the Alice's counter if you were given Bob's counter, or Bob's counter if you were given Alice's counter.

You answer will be considered correct if its absolute or relative error doesn't exceed 10910^{-9} .

输入输出样例

  • 输入#1

    Alice
    3 1
    

    输出#1

    3.500000000
    
  • 输入#2

    Bob
    2 30
    

    输出#2

    2
    
  • 输入#3

    Alice
    2572 10
    

    输出#3

    3439.031415943
    

说明/提示

In the first example, Bob's counter has a 62.5% chance of being 3, a 25% chance of being 4, and a 12.5% chance of being 5.

首页