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 h1 cm from the ground. On the height h2 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 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 2pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
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.
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.
10 30 2 1
1
10 13 1 1
0
10 19 1 2
-1
1 50 5 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.
1
题意:
一大男孩在森林轧马路,毛毛虫爬树摘苹果,毛毛虫距离地面 h1,苹果距离地面 h2 的高度。白天往上爬 a,晚上掉下来 b ,一个九年级的热爱自然的同学,想看看毛毛虫怎么摘到苹果的(我也想看看)!问需要几天后前去该森林观看。
思路:
这尴尬的理解力,晚上是18点开始。
AC code:
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<algorithm>
#define HardBoy main()
#define ForMyLove return 0;
using namespace std;
const int MYDD = 1103;
int HardBoy {
int h1, h2, a, b;
// while(( == 1) != EOF){
scanf("%d %d %d %d", &h1, &h2, &a, &b);
if(h1 + 8*a >= h2) puts("0");//当天就摘到了苹果
else if(a > b){
int Need = h2 - h1 -8*a;
int vv = 12*(a - b);
printf("%d\n", 1+(Need - 1)/vv);
} else
puts("-1");
// }
ForMyLove
}