codeforces 652 A. Gabriel and Caterpillar

编程入门 行业动态 更新时间:2024-10-08 14:50:46

<a href=https://www.elefans.com/category/jswz/34/1770097.html style=codeforces 652 A. Gabriel and Caterpillar"/>

codeforces 652 A. Gabriel and Caterpillar

A. Gabriel and Caterpillar


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 heighth1 cm from the ground. On the heighth2 cm (h2 > h1) 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 bya 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 at10 am and finishes at 10 pm. Gabriel's classes finish at2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at2 pm.

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

Input

The first line contains two integers h1, h2 (1 ≤ h1 < h2 ≤ 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.

Output

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.

Examples Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note

In the first example at 10 pm of the first day the caterpillar gets the height26. At 10 am of the next day it slips down to the height14. 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.


题意:一只毛毛虫从h1高度去h2高度吃苹果,白天每小时上升a厘米,晚上每小时下降b厘米,从当天下午2点开始计算,问几天能到达h2

分析:这题主要是模拟毛毛虫的上升下降过程,数据不大,不会超时,注意到毛毛虫可以下降到地底,在判断-1时需要尤其特判。

#include<cstring>
#include<cstdio>
#include<iostream>using namespace std;int main()
{int h1,h2,a,b;while(scanf("%d%d%d%d",&h1,&h2,&a,&b)!=EOF){if(h1+8*a<h2&&h1+12*a-12*b<=h1){printf("-1\n");continue;}if(a==b&&h1+8*a<h2){printf("-1\n");continue;}int ans=0;while(1){h1+=a*8;if(h1>=h2) break;h1-=b*12;ans++;h1+=a*4;}printf("%d\n",ans);}return 0;}



更多推荐

codeforces 652 A. Gabriel and Caterpillar

本文发布于:2024-02-06 04:03:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1746407.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:codeforces   Caterpillar   Gabriel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!