CodeForces 652A Gabriel and Caterpillar(模拟)
2016-04-04 11:01
471 查看
题意:有一个人,白天每小时爬a米,晚上每小时掉下来b米,可以掉到地下去,你从第0天的下午两点看到这个人在h1,他要到h2去,早上10点到晚上十点算白天,其他算晚上,问你他第几天到达h2,如果不能到达输出-1思路:直接模拟...
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 byb 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 2pm.
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
Input
Output
Input
Output
Input
Output
Input
Output
#include <cstdio> #include <queue> #include <cstring> #include <iostream> #include <cstdlib> #include <algorithm> #include <vector> #include <map> #include <string> #include <set> #include <ctime> #include <cmath> #include <cctype> using namespace std; #define maxn 100000 #define LL long long int cas=1,T; LL h1,h2,a,b; int main() { scanf("%lld%lld%lld%lld",&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) { printf("%d\n",day); return 0; } now = (now+1)%24; if (now==0) day++; } printf("-1\n"); //freopen("in","r",stdin); //scanf("%d",&T); //printf("time=%.3lf",(double)clock()/CLOCKS_PER_SEC); return 0; }
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 byb 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 2pm.
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
Input
10 30 2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19 1 2
Output
-1
Input
1 505 4
Output
1
相关文章推荐
- myBatis(三) xml文件的写法,返回主键,快速生成类jar
- struts2笔记03-ActionContext
- CSS布局中的问题
- Hacker-1
- leetcode---Word Pattern
- 让自己的软件出现在选择打开列表的软件中
- Android 开发艺术与探究 第一章 Activity 的生命周期和启动模式
- 动态数组
- DOS下操作数据库基本语法(简明扼要)
- myBatis(二)方法、控制、接口使用
- swing布局管理器简介
- 数据库中的 Date 函数研究
- 215. Kth Largest Element in an Array
- 记毕设中遇到的菜鸡问题----3
- 【转】理解Java Integer的缓存策略
- POJ2479&&POJ2593 Maximum sum&&Max Sequence(最大连续和)
- 腾讯机试题1:打印蛇形矩阵
- myBatis配置(一)
- java网络编程
- Ten sort algorithms in interviews