Educational Codeforces Round 10(A)模拟

来源:互联网 发布:天津软件培训基地 编辑:程序博客网 时间:2024/05/17 20:00

A. Gabriel and Caterpillar
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
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 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 2 pm.

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.

Examples
input
10 302 1
output
1
input
10 131 1
output
0
input
10 191 2
output
-1
input
1 505 4
output
1
Note

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.



题意:有一只毛毛虫,在高度为h1的地方往h2的地方爬,白天爬的速度是a,晚上掉下的速度是b,每天回在下午2点去查看毛毛虫有没有爬到目的地,问需要等几天,如果不能到达h2那么输出-1.


题解:直接模拟就好啦,输出-1只有一种情况就是速度a<=b,而且第一次爬不到h2,那么就永远都爬不上了。输出-1, 否则就模拟一下就好了



#include<cstdio>  #include<cstring>  #include<cstdlib>  #include<cmath>  #include<iostream>  #include<algorithm>  #include<vector>  #include<map>  #include<set>  #include<queue>  #include<string>  #include<bitset>  #include<utility>  #include<functional>  #include<iomanip>  #include<sstream>  #include<ctime>  using namespace std;    #define N int(1e5)  #define inf int(0x3f3f3f3f)  #define mod int(1e9+7)  typedef long long LL;      #ifdef CDZSC  #define debug(...) fprintf(stderr, __VA_ARGS__)  #else  #define debug(...)   #endif  int main()  {  #ifdef CDZSC      freopen("i.txt", "r", stdin);      //freopen("o.txt","w",stdout);      int _time_jc = clock();  #endif  int a,b,h1,h2;while(~scanf("%d%d%d%d",&h1,&h2,&a,&b)){int h=h2-h1;int v=a-b;int num=0,ans=0;if(a<=b&&num+8*a<h){puts("-1");continue;}while(1){if(num+8*a<h){num+=(12*v);}else{break;}ans++;}printf("%d\n",ans);}#ifdef CDZSC          debug("time: %d\n", int(clock() - _time_jc));  #endif      return 0;  }  












0 0
原创粉丝点击