codeforce-A. Gabriel and Caterpillar(模拟)

A. Gabriel and Caterpillar
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 byb 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.

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 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.


//codeforce-Gabriel and Caterpillar(模拟)
//有一个虫刚开始在h1的高度,有个苹果在h2的高度,已知其白天每小时爬a米,夜晚滑落b米每小时.
//并且规定白天时间是10~22.有个小孩每天2点下课.他想看到虫吃到苹果的场景,问第几天他能看到?
//解题思路:模拟,有解释可知第一天从2点开始算起.以后都是从10点. 
#include<cstdio>
#include<cstring>
int main()
{
	int h1,h2,a,b,i,j,k;
	scanf("%d%d",&h1,&h2);
	scanf("%d%d",&a,&b);
	k=0;
	i=h1;
	j=1;
	while(i<h2)
	{
	  if(j==1)   //第一天 
	  {
	     i=i+a*8; //虫可以到达的高度 
		 j=0;
		 if(a<=b&&i<h2) //如果白天上升的速度小于夜晚下降的速度并且第一天没到达.那么以后也到不了。 
		 {
		    k=-1;break; 	
		 }	
	  }
	  else    //第一天未到,以每天白天其爬的时间都为12. 
	  {
	    i=i+a*12;	
	  }	
	  if(i>=h2)   //吃到苹果,跳出循环 
	  {
	  	break;
	  }
	  else
	  {
	  	k++;      //否则,记录天数.并减去夜晚下降的高度. 
	  	i-=b*12;
	  }
	}
	printf("%d\n",k);
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

bokzmm

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值