A. Gabriel and Caterpillar

题目连接:

http://www.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

题意

有一个人,白天每小时爬a米,晚上每小时掉下来b米,可以掉到地下去

你从第0天的下午两点看到这个人在h1,他要到h2去

早上10点到晚上十点算白天,其他算晚上

问你他第几天到达h2

如果不能到达输出-1

题解:

数学智障很慌,直接暴力模拟好了,啪啪啪就好了

代码

#include<bits/stdc++.h>
using namespace std;long long h1,h2,a,b;
int main()
{cin>>h1>>h2>>a>>b;int now = 14;int day = 0;int t = 0;while(t<1e7){t++;if(now>=10&&now<=21)h1+=a;else h1-=b;if(h1>=h2){cout<<day<<endl;return 0;}now=(now+1)%24;if(now==0)day++;}cout<<-1<<endl;
}

转载于:https://www.cnblogs.com/qscqesze/p/5327835.html

Educational Codeforces Round 10 A. Gabriel and Caterpillar 模拟相关推荐

  1. Educational Codeforces Round 10 C. Foe Pairs —— 后缀和

    题目链接:http://codeforces.com/problemset/problem/652/C C. Foe Pairs time limit per test 1 second memory ...

  2. Educational Codeforces Round 10 C. Foe Pairs

    C. Foe Pairs time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  3. Educational Codeforces Round 10 C. Foe Pairs 水题

    C. Foe Pairs 题目连接: http://www.codeforces.com/contest/652/problem/C Description You are given a permu ...

  4. Educational Codeforces Round 10 B. z-sort

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  5. coderforce Educational Codeforces Round 10 C. Foe Pairs(贪心)

    C. Foe Pairs time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  6. [Educational Codeforces Round 16]A. King Moves

    [Educational Codeforces Round 16]A. King Moves 试题描述 The only king stands on the standard chess board ...

  7. Educational Codeforces Round 114 (Rated for Div. 2) (A ~ F)全题解

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Educational Codeforces Round 114 (Rated for Div. 2) ...

  8. Educational Codeforces Round 32

    http://codeforces.com/contest/888 A Local Extrema[水] [题意]:计算极值点个数 [分析]:除了第一个最后一个外,遇到极值点ans++,包括极大和极小 ...

  9. Educational Codeforces Round 90 (Rated for Div. 2)(A, B, C, D, E)

    Educational Codeforces Round 90 (Rated for Div. 2) Donut Shops 思路 分三种情况: a==c/ba == c / ba==c/b这个时候两 ...

最新文章

  1. 关于学习Python的一点学习总结(28->收集参数及分配参数)
  2. pca主成分分析结果解释_SKLEARN中的PCA(Principal Component Analysis)主成分分析法
  3. linux shell 脚本 获取当前函数名
  4. mybatis plugins_[MyBatis] SpringBoot 整合Mybatis
  5. MySQL行转列完整SQL示例
  6. 桌面云计算机的配置,Citrix桌面云实验环境的部署配置
  7. 关键帧 关于decode_one_frame函数
  8. linux win7 默认启动,请教:我的grub.cfg里面的内容如下,请教怎样改代码才能让WIN7设为默认启动...
  9. 【总结】字符串匹配: KMP 和 拓展KMP
  10. 实验楼linux指令,Linux操作命令(二)
  11. 使用jmeter做接口测试----柠檬不萌!
  12. lua如何打印行号_【Lua与C#交互⑤】Lua中的注册表和引用系统
  13. 数据库系统原理课程设计
  14. Nexus3 安装 及 配置 docker 私有、代理 仓库
  15. 浪潮ERP-PS异速联远程接入解决方案
  16. apt-get安装软件:依赖冲突问题及解决
  17. python实例008--摄氏温度和华氏温度转换
  18. 服务器网站监控报表,宝塔面板网站监控报表实时分析网站日志
  19. 怎么定位前后端问题之-图片显示不出来显示空白等
  20. java提升路线书单(原文自知乎刘欣)

热门文章

  1. dokuwiki 的管理和使用
  2. C/C++中 static 的作用
  3. 操作系统(十二)线程的实现方式、多线程模型
  4. UNIX再学习 -- 内存管理
  5. VirtualApp技术黑产利用研究报告
  6. 从比特币脚本引擎到以太坊虚拟机
  7. 开发者福利:史上最全Android 开发和安全系列工具
  8. c语言赋值小数,c语言中将一个浮点型赋值给整型时,会不会四舍五入?
  9. mybatis批量夺标添加_MyBatis+MySQL同时执行多条SQL,实现多表插入数据
  10. mysql中int(m)_mysql中int(M) tinyint(M)中M的作用