CF65A.Harry Potter and Three Spells
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
A long time ago (probably even in the first book), Nicholas Flamel, a great alchemist and the creator of the Philosopher's Stone, taught Harry Potter three useful spells. The first one allows you to convert a grams of sand into b grams of lead, the second one allows you to convert c grams of lead into d grams of gold and third one allows you to convert e grams of gold into f grams of sand. When Harry told his friends about these spells, Ron Weasley was amazed. After all, if they succeed in turning sand into lead, lead into gold, and then turning part of the gold into sand again and so on, then it will be possible to start with a small amount of sand and get huge amounts of gold! Even an infinite amount of gold! Hermione Granger, by contrast, was skeptical about that idea. She argues that according to the law of conservation of matter getting an infinite amount of matter, even using magic, is impossible. On the contrary, the amount of matter may even decrease during transformation, being converted to magical energy. Though Hermione's theory seems convincing, Ron won't believe her. As far as Ron is concerned, Hermione made up her law of conservation of matter to stop Harry and Ron wasting their time with this nonsense, and to make them go and do homework instead. That's why Ron has already collected a certain amount of sand for the experiments. A quarrel between the friends seems unavoidable...
Help Harry to determine which one of his friends is right, and avoid the quarrel after all. To do this you have to figure out whether it is possible to get the amount of gold greater than any preassigned number from some finite amount of sand.
很久以前(可能甚至在第一本书中),伟大的炼金术士、贤者之石的创造者尼可·勒梅曾教给哈利·波特三个实用的魔咒。第一个魔咒可以将 a 克沙子转化为 b 克铅;第二个魔咒可以将 c 克铅转化为 d 克黄金;第三个魔咒可以将 e 克黄金转化为 f 克沙子。当哈利向朋友们讲述这些魔咒时,罗恩·韦斯莱惊叹不已。毕竟,如果他们能成功地将沙子变成铅,再将铅变成黄金,接着又将部分黄金变回沙子,如此循环往复,那么就可以从少量沙子出发,获得巨量的黄金!甚至可以获得无限多的黄金!而赫敏·格兰杰则对这一想法持怀疑态度。她认为,根据物质守恒定律,即使借助魔法,也不可能凭空创造出无限多的物质。相反,在转化过程中,物质总量甚至可能减少,部分物质会转化为魔法能量。尽管赫敏的理论看似令人信服,罗恩却拒绝相信。在罗恩看来,赫敏编造出这个“物质守恒定律”,只是为了阻止哈利和他自己把时间浪费在这种无聊的事情上,好逼他们去写作业。因此,罗恩早已为实验收集了一定量的沙子。朋友们之间的争执似乎已不可避免……
请帮助哈利判断他的哪位朋友是正确的,从而最终避免这场争执。为此,你需要弄清楚:是否有可能从某个有限量的沙子出发,经过若干次转化后,得到任意预先指定数量以上的黄金?
输入格式
The first line contains 6 integers a, b, c, d, e, f (0 ≤ a, b, c, d, e, f ≤ 1000).
第一行包含 6 个整数 a、b、c、d、e、f(0 ≤ a, b, c, d, e, f ≤ 1000)。
输出格式
Print "Ron", if it is possible to get an infinitely large amount of gold having a certain finite amount of sand (and not having any gold and lead at all), i.e., Ron is right. Otherwise, print "Hermione".
如果在初始仅有有限数量的沙子(且完全没有金子和铅)的情况下,能够获得无限多的金子,则输出“Ron”(即罗恩是正确的);否则,输出“Hermione”。
输入输出样例
输入#1
100 200 250 150 200 250
输出#1
Ron
输入#2
100 50 50 200 200 100
输出#2
Hermione
输入#3
100 10 200 20 300 30
输出#3
Hermione
输入#4
0 0 0 0 0 0
输出#4
Hermione
输入#5
1 1 0 1 1 1
输出#5
Ron
输入#6
1 0 1 2 1 2
输出#6
Hermione
输入#7
100 1 100 1 0 1
输出#7
Ron
说明/提示
Consider the first sample. Let's start with the 500 grams of sand. Apply the first spell 5 times and turn the sand into 1000 grams of lead. Then apply the second spell 4 times to get 600 grams of gold. Let’s take 400 grams from the resulting amount of gold turn them back into sand. We get 500 grams of sand and 200 grams of gold. If we apply the same operations to 500 grams of sand again, we can get extra 200 grams of gold every time. Thus, you can get 200, 400, 600 etc. grams of gold, i.e., starting with a finite amount of sand (500 grams), you can get the amount of gold which is greater than any preassigned number.
In the forth sample it is impossible to get sand, or lead, or gold, applying the spells.
In the fifth sample an infinitely large amount of gold can be obtained by using only the second spell, which allows you to receive 1 gram of gold out of nothing. Note that if such a second spell is available, then the first and the third one do not affect the answer at all.
The seventh sample is more interesting. We can also start with a zero amount of sand there. With the aid of the third spell you can get sand out of nothing. We get 10000 grams of sand in this manner. Let's get 100 grams of lead using the first spell 100 times. Then make 1 gram of gold from them. We managed to receive 1 gram of gold, starting with a zero amount of sand! Clearly, in this manner you can get an infinitely large amount of gold.
考虑第一个样例。我们从 500 克沙子开始:将第一个法术施放 5 次,把沙子转化为 1000 克铅;再将第二个法术施放 4 次,得到 600 克黄金。从所得的黄金中取出 400 克,将其变回沙子,此时我们拥有 500 克沙子和 200 克黄金。若对这 500 克沙子重复上述操作,每次均可额外获得 200 克黄金。因此,可获得的黄金质量为 200,400,600,… 克,即:从有限量的沙子(500 克)出发,可获得任意预先指定的大数质量的黄金。
在第四个样例中,无论怎样施放法术,都无法得到沙子、铅或黄金。
在第五个样例中,仅使用第二个法术即可获得无穷多的黄金——该法术允许你凭空生成 1 克黄金。注意:若存在此类第二个法术,则第一个与第三个法术对答案毫无影响。
第七个样例更有趣。此处我们甚至可以从零克沙子开始:借助第三个法术,可凭空获得沙子,从而得到 10000 克沙子;再利用第一个法术施放 100 次,由沙子得到 100 克铅;最后将这 100 克铅转化为 1 克黄金。这样,我们便成功地从零克沙子出发获得了 1 克黄金!显然,通过这种方式,我们可以获得无穷多的黄金。
输入解题思路,AI测评打分。不知道怎么写?