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 ...
随机推荐
- nodejs基础 -- 函数
Node.js 函数 在JavaScript中,一个函数可以作为另一个函数接收一个参数.我们可以先定义一个函数,然后传递,也可以在传递参数的地方直接定义函数. Node.js中函数的使用与Javasc ...
- DM816x算法具体解释--之OSD
简单介绍: 本文介绍DM8168 DVRRDK中传入DSP内部的视频格式以及大概的处理流程. 背景: 可能有非常多人为了加快研发的速度.减少难度,选择在DVRRDk已有的OSD内加入自己的DSP算法. ...
- QButtonGroup:按钮类的非可视化容器,默认可实现按钮的子类实例的单选。
QButtonGroup The QButtonGroup class provides a container to organize groups of button widgets. QButt ...
- 很好的hadoop学习博客实际操作训练(旧版本)
实际操作 http://www.cnblogs.com/xia520pi/archive/2012/05/16/2504205.html 流程解析 http://www.cnblogs.com/spo ...
- 搭建 FTP 文件服务vsftpd
安装并启动 FTP 服务 安装 VSFTPD 使用 yum 安装 vsftpd: yum install vsftpd -y vsftpd 是在 Linux 上被广泛使用的 FTP 服务器,根据其[官 ...
- android 开发者资源下载地址记录(转+补充)
https如果无法下载的话将下面的:https://dl-ssl 部分改为 http://dl (1)Android SDK (Android SDK主安装包,包含SDK Manager.AVD Ma ...
- Android中SurfaceView用法示例
SurfaceView在游戏开发中有着举足轻重的地位,它对于画面的控制有着更大的自由度(不像View要用handler来更新,关于View的),但这方面的参考资料并不是太多,能找到的例子都有点喧宾夺主 ...
- 浅谈ITIL
本节内容 浅谈ITIL CMDB介绍 Django自定义用户认证 Restful 规范 资产管理功能开发 浅谈ITIL TIL即IT基础架构库(Information Technology Infra ...
- java.lang.OutOfMemoryError 错误分类
java.lang.OutOfMemoryError: Java heap space原因:Heap内存溢出,意味着Young和Old generation的内存不够.解决:调整java启动参数 -X ...
- 安装autoit libary失败问题解决
运行环境:win7-32,python2.7安装遇到的问题: