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

水题,模拟即可

#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;
}

Code Forces 652A Gabriel and Caterpillar的更多相关文章

  1. CodeForces 652A Gabriel and Caterpillar

    简单模拟. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...

  2. codeforces 652A A. Gabriel and Caterpillar(水题)

    题目链接: A. Gabriel and Caterpillar time limit per test 1 second memory limit per test 256 megabytes in ...

  3. 思维题--code forces round# 551 div.2

    思维题--code forces round# 551 div.2 题目 D. Serval and Rooted Tree time limit per test 2 seconds memory ...

  4. Educational Codeforces Round 10 A. Gabriel and Caterpillar 模拟

    A. Gabriel and Caterpillar 题目连接: http://www.codeforces.com/contest/652/problem/A Description The 9-t ...

  5. Code Forces 796C Bank Hacking(贪心)

    Code Forces 796C Bank Hacking 题目大意 给一棵树,有\(n\)个点,\(n-1\)条边,现在让你决策出一个点作为起点,去掉这个点,然后这个点连接的所有点权值+=1,然后再 ...

  6. Code Forces 833 A The Meaningless Game(思维,数学)

    Code Forces 833 A The Meaningless Game 题目大意 有两个人玩游戏,每轮给出一个自然数k,赢得人乘k^2,输得人乘k,给出最后两个人的分数,问两个人能否达到这个分数 ...

  7. Code Forces 543A Writing Code

    题目描述 Programmers working on a large project have just received a task to write exactly mm lines of c ...

  8. code forces 383 Arpa's loud Owf and Mehrdad's evil plan(有向图最小环)

    Arpa's loud Owf and Mehrdad's evil plan time limit per test 1 second memory limit per test 256 megab ...

  9. code forces 382 D Taxes(数论--哥德巴赫猜想)

    Taxes time limit per test 2 seconds memory limit per test 256 megabytes input standard input output ...

随机推荐

  1. 【转】【C++】C++ 中的线程、锁和条件变量

    线程 类std::thread代表一个可执行线程,使用时必须包含头文件<thread>.std::thread可以和普通函数,匿名函数和仿函数(一个实现了operator()函数的类)一同 ...

  2. Eclipse 调试总进入Spring代理的解决办法

    一直都是跳入代理类中,手动切换查看内容,还以为别人也是这样,结果被告知不是.瞬间囧囧. 搜了一番,看起来有两个办法. 第一个:使用step filter,过滤掉不需要的package.--未测试 第二 ...

  3. C++类的成员函数的形参列表后面的const

    看到(C++ Primer)类的成员函数这里,突然对成员函数形参列表后面的const感到迷惑. 因为书中开始说是修饰隐含形参this的,然后又说是声明该函数是只读的. 大为不解! 翻资料.找人讨论.. ...

  4. php Laravel 框架之建立后台目录

    今天研究了在Laravel框架中的控制器中加入后台的目录.发现了一些小的规律,拿来和大家分享一下吧. 通常情况下,我们是直接在controllers目录中加入我们的控制器,然后再routes.php ...

  5. Swift数值运算

    Swift 让全部数值类型都支持了主要的四则运算: 加法(+) 减法(-) 乘法(*) 除法(/) 1 + 2 // 等于 3 5 - 3 // 等于 2 2 * 3 // 等于 6 10.0 / 2 ...

  6. myslq的索引类型为MyISAM和BDB的表:复合索引下的自增长

    本文源自:http://www.himigame.com/mysql/781.html 3.6.9. 使用AUTO_INCREMENT 可以通过AUTO_INCREMENT属性为新的行产生唯一的标识: ...

  7. php对gzip的使用(理论)

    gzip是GNU zip的缩写,它是一个GNU自由软件的文件压缩程序,也经常用来表示gzip这种文件格式.软件的作者是Jean-loup Gailly和Mark Adler.1992年10月31日第一 ...

  8. 数据结构 http://www.cnblogs.com/sun-haiyu/p/7704654.html

    数据结构与算法--从平衡二叉树(AVL)到红黑树 上节学习了二叉查找树.算法的性能取决于树的形状,而树的形状取决于插入键的顺序.在最好的情况下,n个结点的树是完全平衡的,如下图“最好情况”所示,此时树 ...

  9. Unity3D工程源码目录

    2-0    暗黑破坏神3 链接:http://pan.baidu.com/s/1dEAUZoX 密码:cly4 2-1    炉石传说 客户端加服务器端 链接:http://pan.baidu.co ...

  10. WinSock1.1和WinSock2.0

    网络编程很重要,说到网络编程就不得不提Socket编程. Windows提供了Windows Socket API(简称WSA),WinSock,目前有两个版本:WinSock1.1 and WinS ...