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 ...
随机推荐
- The request lifetime scope cannot be created because the HttpContext is not available
项目中应用了Autofac,在Global轮询处理Job的时候,需要获取现有得Service,而这些Service已经通过Autofac进行了配置,所以理所应当的用下面的代码去获取了. Depende ...
- PHPExcel正确读取excel表格时间单元格(转载)
error_reporting(E_ALL); date_default_timezone_set('Asia/shanghai'); /** PHPExcel_IOFactory */ requir ...
- jquery日期插件datePicker
index.html <!DOCTYPE html> <html lang="zh-cn"> <head> <meta http-equi ...
- c++ list erase()
STL中的容器按存储方式分为两类,一类是按以数组形式存储的容器(如:vector .deque):另一类是以不连续的节点形式存储的容器(如:list.set.map).在使用erase方法来删除元素时 ...
- 【Raspberry Pi】openwrt 路由
http://blog.sina.com.cn/s/blog_40983e5e0102v6qt.html
- 【matlab】error:试图访问 im2(1,1211);由于 size(im2)=[675,1210],索引超出范围。
试图访问 im2(1,1211):由于 size(im2)=[675,1210],索引超出范围. 出错 dect (line 14) if abs((im2(i,j))-(im1(i,j)))> ...
- linux环境下,清空history中记录的历史命令
需求描述: 今天在数据库主机上操作,通过history看到有刚操作过的历史记录,想把这个清除了, 但是,还不影响后续的命令记录,所以查了下,在此记录. 操作过程: 1.通过history -c命令,完 ...
- 几张图轻松理解String.intern()
https://blog.csdn.net/soonfly/article/details/70147205 在翻<深入理解Java虚拟机>的书时,又看到了2-7的 String.inte ...
- layui时间,table,大图查看,弹出框,获取音频长度,文件上传
1.引入: <link href="../../Scripts/layui-v2.3.0/css/layui.css" rel="stylesheet" ...
- oracle 日期函数 求年的最后一天、第一天,月的最后一天
add_months(trunc(to_date('2013','yyyy') ,'yyyy'),12)-1 2013年最后一天 trunc(to_date('2013','yyyy') ,'yyy ...