Problem Statement
A Fountain of Life is a special fountain that produces the elixir of life at a constant speed of elixir liters per second. A dark mage managed to cast a Curse of Death on the Fountain so in addition to the elixir it now produces a deadly poison at a constant speed of poison liters per second. Both the poison and elixir are collected in an infinitely large pool around the Fountain and form a mixture. The mixture will become deadly once the percentage of poison in the mixture is at least 50%. Your task is to calculate the time at which the mixture will become deadly. At the beginning (0-th second) the pool contains pool liters of 100% elixir.
Your program must return a double, the time in seconds at which the mixture becomes deadly. If the mixture never becomes deadly, return -1.0.
Definition
Class:
FountainOfLife
Method:
elixirOfDeath
Parameters:
int, int, int
Returns:
double
Method signature:
double elixirOfDeath(int elixir, int poison, int pool)
(be sure your method is public)
Notes
-
The returned value must be accurate to within a relative or absolute value of 1E-9.
Constraints
-
elixir will be between 1 and 10000, inclusive.
-
poison will be between 1 and 10000, inclusive.
-
pool will be between 1 and 10000, inclusive.
Examples
0)
1
2
2
Returns: 2.0
At t = 0s there are 2 liters of 100% elixir.
At t = 1s there are 3 liters of elixir and 2 liters of poison for a total volume of 5 liters. 2 liters of poison is 40% of 5 liters so the mixture is still not deadly.
At t = 2s there are 4 liters of elixir and 4 liters of poison for a total volume of 8 liters. 4 liters of poison is exactly 50% of the mixture so it is now deadly.
1)
200
100
1
Returns: -1.0
With 200 liters of elixir per second and only 100 liters of poison per second, the mixture never becomes deadly.
2)
9999
10000
10000
Returns: 10000.0
It might take a long time for the mixture to become deadly.
3)
1
10000
1
Returns: 1.0001000100010001E-4
On the other hand, it might take a short time for the mixture to become deadly.
4)
40
43
41
Returns: 13.666666666666666
public class FountainOfLife { public double elixirOfDeath(int elixir, int poison, int pool) { if (elixir >= poison) return -1.0; return (pool + 0.0) / (poison - elixir); } }
发表评论
-
TCHS-12-950
2010-03-01 12:58 784Problem Statement ... -
TCHS-12-550
2010-03-01 10:04 707Problem Statement ... -
TCHS-12-250
2010-02-28 09:53 721Problem Statement ... -
TCHS-11-1000
2010-02-22 15:22 671Problem Statement ... -
TCHS-11-500
2010-02-22 13:11 799Problem Statement ... -
TCHS-11-250
2010-02-22 11:38 721Problem Statement ... -
TCHS-10-1000
2010-02-21 16:35 690Problem Statement ... -
TCHS-10-500
2010-02-21 15:16 765Problem Statement ... -
TCHS-10-250
2010-02-21 14:26 768Problem Statement ... -
TCHS-9-1000
2010-02-20 18:45 704Problem Statement ... -
TCHS-9-500
2010-02-20 16:26 1329Problem Statement ... -
TCHS-9-250
2010-02-20 15:24 690Problem Statement ... -
TCHS-8-1000
2010-02-19 11:57 688Problem Statement ... -
TCHS-8-500
2010-02-19 10:56 760Problem Statement ... -
TCHS-8-250
2010-02-19 10:18 616Problem Statement ... -
TCHS-7-1000
2010-02-05 15:21 692Problem Statement ... -
TCHS-7-500
2010-02-05 13:45 694Problem Statement ... -
TCHS-7-250
2010-02-05 13:32 781Problem Statement ... -
TCHS-6-900
2010-02-04 12:06 677Problem Statement ... -
TCHS-6-600
2010-02-04 11:33 709Problem Statement ...
相关推荐
TCHS-SRM-1 SRM - 算法单轮比赛 2. USACO - C++11 礼物1.cpp 骑车.cpp 测试.cpp 3.乌拉尔 - - C++11,Java 1.8 乌拉尔在线法官的可能解决方案 反向Root.cpp 总和文件 求和程序 最终排名.cpp 磁暴.cpp 磁暴.java 寂寞...
2. **C语言编程实践** - 文件包含了C语言代码示例 - 涉及到的基本输入输出操作 - 数学函数的应用 - 循环结构与条件判断 - 数据类型与变量定义 ### 3G移动通信技术详解 #### WCDMA (宽带码分多址) - **技术...
TCHs(时隙分配)、TRXSIG(发射信号)和OMUSIG(操作维护信道)是需要配置的。 5. **电源模块**:DE34基站的公共设备直流电源由CSUA模块提供。 6. **GSM多址方式**:GSM系统采用FDMA(频分多址)和TDMA(时分多址...
4. 配置ULTRASITE传输时,不需要配置EDAP(可能是指电子数据接入点),而需要配置TCHs(时隙信道)、TRXSIG(传输信号)和OMUSIG(操作维护信号)。 5. DE34基站的公共设备直流电源由CSUA模块提供,而非PWSB、PSUA...
电路交换业务信道(TCHs)测试是BER测试的重要组成部分,主要用于评估语音和低速数据服务的质量。这一部分将详细介绍如何设置测试环境并执行测试。 #### 分组数据业务信道(PDTCHs)测试 随着数据传输速度的提高,...
要告诉技术人员验证元素,请将“tchs”属性添加到元素。 <input type="text" tchs=""></input> 技术人员利用规则来验证元素。 验证是在每个元素的基础上完成的,并且根据所使用的元素进行不同的工作...
此外,TopCoder竞赛提供了丰富的奖金和机会,如TopCoder Open(TCO)、TopCoder Collegiate Challenge(TCCC)和TopCoder High School(TCHS)等,涵盖算法、设计、开发和组装等领域。TopCoder Studio则专注于网页...