CodeChef: Codechef
Site under maintenance
  • Register
  • Forgot Password?
  • PRACTICE
    • Easy
    • Medium
    • Hard
  • COMPETE
    • August Mini Challenge
    • August Algorithm Challenge
    • July Algorithm Challenge
    • June Algorithm Challenge
    • May Gamers Challenge
  • DISCUSS
    • Forums
    • Blog
    • Twitter
  • COMMUNITY
    • CodeChef TechTalks
    • CodeChef Meetups
    • Campus Chapters
    • Host Your Contest
    • User Groups
  • HELP
    • Frequently Asked Questions
    • FAQ for Problem Setters
    • Tutorial: Paying Up
    • Tutorial: Small Factorials
    • Tutorial: Input and Output(I/O)
    • Tutorial: Your First Non-Trivial Problem
  • ABOUT
    • About CodeChef
    • About Directi
    • CEO's Corner
    • Press Room
    • Careers

Home » Problems (medium) » Ciel and Battle Arena

Ciel and Battle Arena

Problem code: CIELBTL

  • Submit
  • All submissions

All submissions for this problem are available.

Chef Ciel bought a new video game for guests to kill time until their orders arrive. In this game, you are a fighter in a battle arena, and you will fight against a fighter called Shindannin. In Japan, many people believe that the next day will be a happy day if they beat Shindannin, otherwise the next day will be an unhappy day.

Let's start by defintions of some variables. VA and VB denote your initial HP (health points) and Shindannin's initial HP respectively. SA and SB denote your strength and Shindannin's strength respectively. MA denotes your initial MP (magical points), which is used when you use a skill. Note that only you can use a skill in the battle.

In each turn, the battle will go on as follows:

  • Firstly, you can use a skill as many times as you like as long as your MP is positive. If you use a skill, your HP and Shindannin's HP are decreased by half and your MP is decreased by 1. If HP becomes a non-integer, HP will be rounded up to the nearest integer. To be more precise, new HP will be ceil(old HP / 2).
  • Next, an integer s is chosen in [0, SA] uniformly randomly, and an integer t is chosen in [0, SB] uniformly randomly.
  • Then, your HP is decresed by t, and Shindannin's HP is decreased by s simultaneously.
  • If both fighter have positive HP, next turn will occur.

When a fighter's HP is down to zero or a negative integer, this fighter loses. If both fighters' HP is down to zero or negative integer simultaneously, you will fight against Shindannin again with the same conditions, that is, HP and MP are recovered completely before next battle. There is no limit on the number of rematches. If you fight optimally, what is your winning percentage?

Input

An input contains 5 integers VA, VB, SA, SB and MA.

Output

Print the maximum winning percentage you can achieve. This value must have an absolute error no more than 10-6.

Constraints

1 ≤ VA, VB ≤ 100
1 ≤ SA, SB ≤ 100
0 ≤ MA ≤ 5

Sample Input 1

5 5 3 3 0

Sample Output 1

0.5

Sample Input 2

5 5 3 3 1

Sample Output 2

0.58886609097948

Sample Input 3

58 85 8 13 0

Sample Output 3

0.00011046536069


Date:2011-11-23
Time limit:1.5s
Source limit:50000B
Languages:All


  • Submit

Comments

Loading Comments...

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Loading Submissions...

RECENT ACTIVITY FOR THIS PROBLEM:

Loading Recent Activity...

HELP

Program should read from standard input and write to standard output.

After you submit a solution you can see your results by clicking on the [My Submissions] tab on the problem page. Below are the possible results:

  • Accepted Your program ran successfully and gave a correct answer. If there is a score for the problem, this will be displayed in parenthesis next to the checkmark.
  • Time Limit Exceeded Your program was compiled successfully, but it didn't stop before time limit. Try optimizing your approach.
  • Wrong Answer Your program compiled and ran succesfully but the output did not match the expected output.
  • Runtime Error Your code compiled and ran but encountered an error. The most common reasons are using too much memory or dividing by zero. For the specific error codes see the help section.
  • Compilation Error Your code was unable to compile. When you see this icon, click on it for more information.

If you are still having problems, see a sample solution here.

  • About CodeChef
  • About Directi
  • CEO's Corner
  • Careers
  • feedback@codechef.com

© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs

Sponsors
The time now is: