在浙江省选二试集训的第一天下午,杭州学军中学的**mjy0724**大姐姐给我们讲了来自于**TopCoder Open 2017**的题目。(**TopCoder Open**系列的比赛分为3个环节5个部分。有海选Round123,半决赛SEMIFINAL和总决赛FINAL。**TopCoder**是一个外国的编程网站,但也面向中国开放。不过主要面向顶尖的高中生和大学生进行全球的交流与切磋。~~而且最重要的是它在中国的连接不是很稳定,总是要加载好久,应该要翻墙。~~)
这是我第一次在TopCoder上交题,也是第一次用类交题。刚开始还不会用,一窍不通。不过在[daklqw](https://www.luogu.org/space/show?uid=22066)和[网上文章](http://acmicpc.info/archives/164)的帮助下,我还是有点懂了。现在还在摸索中……[心得](https://21391.blog.luogu.org/TopCoder-With-OJ-Problem-class)
英文题面 English Problem
Problem Statement
代码
You are in a spaceship that is far away from the Earth. Your crew needs costH2O moles of water (H2O) and costO2 moles of oxygen (O2) per day. The spaceship currently has remainH2O moles of water and remainO2 moles of oxygen left in the tanks. This ship is old so you don't have any equipment to recycle used water and oxygen: once you use them, they are gone. The only thing you can do is electrolysis of water. For any positive real x, you can electrolyze x moles of water. You will lose those x moles of water but you will produce x/2 moles of oxygen. (You will also produce x moles of hydrogen but those don't matter in this task.)
Compute and return the longest amount of time (in days) your crew can survive. Note that the answer is not necessarily an integer.
Definition
代码
Class: WaterAndOxygen
Method: maxDays
Parameters: int, int, int, int
Returns: double
Method signature: double maxDays(int remainH20, int remainO2, int costH2O, int costO2)
(be sure your method is public)
Limits
代码
Time limit (s): 2.000Memory limit (MB): 256
Notes
代码
The returned value must have an absolute or relative error less than 1e-9.
Constraints
代码
costH2O will be between 1 and 1,000,000,000, inclusive.
costO2 will be between 1 and 1,000,000,000, inclusive.
remainH2O will be between 0 and 1,000,000,000, inclusive.
remainO2 will be between 0 and 1,000,000,000, inclusive.
Examples
0)
代码
64 70 3 7
Returns: 12.0
If you don't do anything, after 70 / 7 = 10 days you will run out of oxygen. At that time you will have 64 - 10 * 3 = 34 moles of water left. In order to survive longer you will need to electrolyze some of your remaining water to produce the oxygen you need. To get enough oxygen for a day, you need to electrolyze 2 * 7 = 14 moles of water. Don't forget that you also need 3 moles of actual water per day. Thus, on each of the following days you will consume 17 moles of water, which means that you can survive for 34 / 2 = 2 extra days. In total you will survive for 10 + 2 = 12 days.
1)
代码
99 102 1 1
Returns: 99.0
You will run out of water after 99/1 = 99 days, while the oxygen will last for 102/1 = 102 days. Electrolysis won't help you live longer than 99 days.
2)
代码
101 99 1 1
Returns: 99.66666666666667
This time you should use 4/3 of a mole of water to produce 2/3 of a mole of oxygen.
0 0 13 27
Returns: 0.0
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.