Code Forces 652A Gabriel and Caterpillar
1 second
256 megabytes
standard input
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.
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.
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.
10 30
2 1
1
10 13
1 1
0
10 19
1 2
-1
1 50
5 4
1
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的更多相关文章
- CodeForces 652A Gabriel and Caterpillar
简单模拟. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...
- codeforces 652A A. Gabriel and Caterpillar(水题)
题目链接: A. Gabriel and Caterpillar time limit per test 1 second memory limit per test 256 megabytes in ...
- 思维题--code forces round# 551 div.2
思维题--code forces round# 551 div.2 题目 D. Serval and Rooted Tree time limit per test 2 seconds memory ...
- Educational Codeforces Round 10 A. Gabriel and Caterpillar 模拟
A. Gabriel and Caterpillar 题目连接: http://www.codeforces.com/contest/652/problem/A Description The 9-t ...
- Code Forces 796C Bank Hacking(贪心)
Code Forces 796C Bank Hacking 题目大意 给一棵树,有\(n\)个点,\(n-1\)条边,现在让你决策出一个点作为起点,去掉这个点,然后这个点连接的所有点权值+=1,然后再 ...
- Code Forces 833 A The Meaningless Game(思维,数学)
Code Forces 833 A The Meaningless Game 题目大意 有两个人玩游戏,每轮给出一个自然数k,赢得人乘k^2,输得人乘k,给出最后两个人的分数,问两个人能否达到这个分数 ...
- Code Forces 543A Writing Code
题目描述 Programmers working on a large project have just received a task to write exactly mm lines of c ...
- 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 ...
- code forces 382 D Taxes(数论--哥德巴赫猜想)
Taxes time limit per test 2 seconds memory limit per test 256 megabytes input standard input output ...
随机推荐
- 后序线索二叉树中查找结点*p的后继
在后序线索二叉树中查找结点*p的后继: 1.若结点*p为根,则无后继:2.若结点*p为其双亲的右孩子,则其后继为其双亲:3.若结点*p为其双亲的左孩子,且双亲无右子女,则其后继为其双亲:4.若结点*p ...
- 学习:erlang的不定长数据包头部。
- 简单html弹窗
css: <style type="text/css"> .moneyrecord { display:none; border:0.5em solid #00AAEE ...
- 讨论CSS中的各类居中方式
今天主要谈一谈CSS中的各种居中的办法. 首先是水平居中,最简单的办法当然就是 margin:0 auto; 也就是将margin-left和margin-right属性设置为auto,从而达到水平居 ...
- HEVC compressGOP 接口
HEVC编码调用compressGOP()来实现一个GOPSize 图像序列的编码.在reference code里,真正做compressGOP编码之前,需要存GOPSize帧YUV在m_cList ...
- crc16算法,包括单片机和c#版本
c语言的#include <stdio.h> static short const wCRC16Table[256] = { 0x0000, 0xC0C1, 0xC181 ...
- mybatis由浅入深day02_7.4mybatis整合ehcache_7.5二级缓存应用场景_7.6二级缓存局限性
7.4 mybatis整合ehcache EhCache 是一个纯Java的进程内缓存框架,是一种广泛使用的开源Java分布式缓存,具有快速.精干等特点,是Hibernate中默认的CacheProv ...
- shell基础(七)-条件语句
条件语句在编写脚本经常遇到:用于处理逻辑问题. 一 IF 语句 if 语句通过关系运算符判断表达式的真假来决定执行哪个分支.Shell 有三种 if ... else 语句: if ... fi 语句 ...
- ASP代码审计学习笔记 -3.上传漏洞
1.ASP上传过程抓包分析: POST /4.asp HTTP/1.1 Host: 192.168.1.102 User-Agent: Mozilla/5.0 (Windows NT 10.0; WO ...
- Python 对目录做遍历
os.walk() 用于遍历目录里的文件,或者说迭代目录里的文件 ??? 什么意思?比如 Linux 中 find /data -type f 表示找出 /data 目录下的所有文件,它会先找出 /d ...