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 ...
随机推荐
- android NavigationBar 显示
android连接7inch屏时,虚拟按键会显示到右侧,变成一条黑边,并且只有back功能. 在连接10inch的时候,虚拟按键就正常,显示在屏幕的底部.有back,home,recent app三个 ...
- 单精度浮点数(float)加法计算出错
场景: 一个float型的变量赋值1170601,加上19000000,结果出现错误. 原因: float占用4个字节(32位)存储空间,包括符号位1位,阶码位8位,尾数23位.浮点数精度与它的尾数有 ...
- hunnu--11547--你的组合数学学得怎样?
你的组合数学学得怎样? Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB Total submit users: ...
- 【Java面试题】30 子线程循环10次,接着主线程循环100,接着又回到子线程循环10次,接着再回到主线程又循环100,如此循环50次,请写出程序。
题目如下: 子线程循环10次,接着主线程循环100,接着又回到子线程循环10次, 接着再回到主线程又循环100,如此循环50次 思路如下: 子线程语主线程为互斥,可用SYNCHRONIZED.很容易想 ...
- Unity UI大小动态设置(Resize Unity UI RectTransform)
我们在开发过程中发现,要调整Unity UI元素的大小,RectTransform提供了sizeDelta属性可以用来动态修改RectTransform的大小,但同时我们也google到另外一个修改R ...
- NPOI从数据库中调取数据直接导出到EXCEL中
关于NPOI NPOI是POI项目的.NET版本,是由@Tony Qu(http://tonyqus.cnblogs.com/)等大侠基于POI开发的,可以从http://npoi.codeplex. ...
- VS2013+opencv2.4.9配置
VS2013+opencv2.4.9(10)配置[zz] - yifeier12 - 博客园 http://www.cnblogs.com/cuteshongshong/p/4057193.html ...
- iOS-WKWebView使用
使用代码:可直接粘贴到自己项目中使用 .h #import "BaseViewController.h" @interface LinkNewsController : BaseV ...
- 静态变量数组实现LRU算法
LRU算法的解释详情请见 https://baike.baidu.com/item/LRU/1269842 这里百度百科给出的比较详细,然后后面有一个例子 说 LRU(least recently u ...
- Javascript 字符串替换
<!DOCTYPE html><html><head> <meta http-equiv="Content-Type" content=& ...