CF652A.Gabriel and Caterpillar

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height _h_1 cm from the ground. On the height _h_2 cm (_h_2 > _h_1) on the same tree hung an apple and the caterpillar was crawling to the apple.

Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.

In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.

Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.

九年级学生加布里埃尔在放学后于森林中散步时,发现一棵树上有一只毛毛虫。此时毛毛虫位于离地面 h1h_1 厘米的高度。在同一棵树上、离地面 h2h_2 厘米(h2>h1h_2 > h_1)的高度挂着一个苹果,而毛毛虫正朝着苹果爬行。

加布里埃尔很想知道毛毛虫何时能到达苹果。他观察到:毛毛虫在白天每小时向上爬 aa 厘米,而在夜晚每小时向下滑 bb 厘米。

加布里埃尔应在多少天后返回森林,才能恰好看到毛毛虫抵达苹果?你可以认为:一天从上午 10 点开始,至晚上 10 点结束。加布里埃尔的课程在下午 2 点结束,且他正是在下午 2 点刚下课时发现毛毛虫的。

注意:这片森林具有魔力,因此毛毛虫可以滑入地下,之后再向上爬向苹果。

输入格式

The first line contains two integers _h_1, _h_2 (1 ≤ _h_1 < _h_2 ≤ 105) — the heights of the position of the caterpillar and the apple in centimeters.

The second line contains two integers a, b (1 ≤ a, b ≤ 105) — the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.

第一行包含两个整数 h1h_1、h2h_2(1≤h1<h2≤1051 \leq h_1 < h_2 \leq 10^5)——分别表示毛毛虫和苹果所在位置的高度(单位:厘米)。

第二行包含两个整数 aa、bb(1≤a,b≤1051 \leq a, b \leq 10^5)——分别表示毛毛虫每天白天向上爬升的距离和每晚向下滑落的距离(单位:厘米/小时)。

输出格式

Print the only integer k — the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.

If the caterpillar can't get the apple print the only integer  - 1.

输出唯一的整数 kk —— 即加布里埃尔应等待的天数,以便返回森林并看到毛毛虫取到苹果。

如果毛毛虫无法取到苹果,则输出唯一的整数 −1-1。

输入输出样例

  • 输入#1

    10 30
    2 1

    输出#1

    1
  • 输入#2

    10 13
    1 1

    输出#2

    0
  • 输入#3

    10 19
    1 2

    输出#3

    -1
  • 输入#4

    1 50
    5 4

    输出#4

    1

说明/提示

In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.

Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.

在第一个例子中,毛虫在第一天晚上10点到达高度26。在第二天上午10点,它滑落到高度14。最终,它在同一天下午6点到达苹果处。

注意,在最后一个例子中,毛虫曾滑落到地面以下,并于次日到达苹果处。

输入解题思路,AI测评打分。不知道怎么写?

首页