前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Code Forces 652A Gabriel and Caterpillar

Code Forces 652A Gabriel and Caterpillar

作者头像
ShenduCC
发布2018-04-26 15:00:35
4380
发布2018-04-26 15:00:35
举报
文章被收录于专栏:算法修养算法修养

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

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

代码语言:javascript
复制
10 30
2 1

output

代码语言:javascript
复制
1

input

代码语言:javascript
复制
10 13
1 1

output

代码语言:javascript
复制
0

input

代码语言:javascript
复制
10 19
1 2

output

代码语言:javascript
复制
-1

input

代码语言:javascript
复制
1 50
5 4

output

代码语言:javascript
复制
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.

水题,模拟即可

代码语言:javascript
复制
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <stdio.h>

using namespace std;
int h1,h2;
int a,b;
int ans=0;
int main()
{
    scanf("%d%d",&h1,&h2);
    scanf("%d%d",&a,&b);
    h1+=a*8;
    if(h1>=h2)
        printf("0\n");
    else if(h1<h2&&b>=a)
        printf("-1\n");
    else if(h1<h2&&b<a)
    {
        int num1=(h2-h1)%((a-b)*12);
        if(num1==0)
            printf("%d\n",(h2-h1)/((a-b)*12));
        else
            printf("%d\n",(h2-h1)/((a-b)*12)+1);
    }
    return 0;
}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2016-03-29 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档