• CodeForces


    题目链接:http://codeforces.com/problemset/problem/652/A

    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 bcm 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
    Copy
    10 30
    2 1
    output
    Copy
    1
    input
    Copy
    10 13
    1 1
    output
    Copy
    0
    input
    Copy
    10 19
    1 2
    output
    Copy
    -1
    input
    Copy
    1 50
    5 4
    output
    Copy
    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.

    题目意思:有一只毛毛虫,在当天下午2:00的时候它在 h1 位置,现在它要到达 h2 的位置上,它在白天上爬速度为a,晚上下滑速度为b(白天:10:00到22:00向上爬;晚上:22:00到10:00下滑)。问要过几天它才能到达 h2 的位置上,如果到不了输出-1.

    题目思路:这道题目很简单但是考理解。不耐心看懂是过不了的 本人先wa了一发再说。。。思路的话直接看代码注释吧。

    #include<stdio.h>
    int main()
    {
        int h1,h2,v1,v2;
        scanf("%d%d%d%d",&h1,&h2,&v1,&v2);
        if(v1<=v2)//晚上比白天速度慢或者相等速度 
        {
            int dis=h2-h1;
            if(dis<=8*v1)printf("0
    ");//要么当天(第0天)14:00到22:00时间段到了 
            else printf("-1
    ");//不然永远到不了 
        }
        else//白天速度快 
        {
            int dis=h2-h1;int v=v1-v2;
            if(dis<=8*v1)printf("0
    ");//要么当天到 
            else 
            {
                dis-=8*v1;v=12*v;//不然的话除去先前走的8小时求剩下的路程 并且求出每天走的净位移 
                if(dis%v)printf("%d
    ",dis/v+1);//2.否则多的路程得多算一天 
                else printf("%d
    ",dis/v);//1.如果恰好能走完 
            }
        }
        return 0;
    } 
  • 相关阅读:
    C#计算两个日期之间相差的天数
    js字符串转时间
    mysql find_in_set 函数
    css控制网页所有图片当图片大于指定宽度图片等于指定宽度
    网页自动适应手机屏幕宽度的方法
    c# 生成指定范围的数字和字母组合随机数
    SqlServer 查看被锁的表和解除被锁的表
    C#隐情信息(银行账户,身份证号码,名字)中间部分特殊字符替换(*)
    c#检查SQL语法是否正确,不执行SQL语句
    sqlserver中的表值函数和标量值函数
  • 原文地址:https://www.cnblogs.com/Mingusu/p/11839092.html
Copyright © 2020-2023  润新知