CF Edu10 A

题目连接

http://codeforces.com/contest/652/problem/A

Description

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.

Sample Input

10 30
2 1

Sample Output

1

Hint

题意

毛毛虫爬树,树上有一个苹果,问毛毛虫能否吃到苹果,如果行,问是在哪天

题解

只有第一天白天是8个小时,其他时候都算是白天和夜晚各12个小时,只要注意不仅仅是白天爬得小于晚上就不能爬到,只要距离足够小,第一天白天爬到就也可以拿到苹果

代码

#include<bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
    int pos,app;
    cin>>pos>>app;
    int up,down;
    cin>>up>>down;
    int ans=0;
    if (up==down)
    {
        if (pos+8*up>=app)
        {
            printf("0\n");
            return 0;

        }
        else{
            printf("-1\n");
            return 0;
        }
    }
    pos+=8*up;
    while(pos>0&&pos<app){
        if (pos==app)
        {
            break;
        }
        pos+=12*(up-down);
        ans++;
    }
    if (pos>=app)
    {
        printf("%d\n",ans );
    }
    else{
        printf("-1\n");
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值