首页 > 其他分享 >Code Forces 652A Gabriel and Caterpillar

Code Forces 652A Gabriel and Caterpillar

时间:2022-10-18 14:07:51浏览次数:49  
标签:652A h2 Gabriel h1 caterpillar Caterpillar include day

A. Gabriel and Caterpillar

time limit per test

memory limit per test

input

output

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.

a cm per hour by day and slips down by b

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

Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.

Input

h1, h2 (1 ≤ h1 < h2 ≤ 105) — the heights of the position of the caterpillar and the apple in centimeters.

a, b (1 ≤ a, b ≤ 105) — the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.

Output

k

 - 1.

Examples

input

10 30
2 1

output

1

input

10 13
1 1

output

0

input

10 19
1 2

output

-1

input

1 50
5 4

output

1

Note

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

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;
}





标签:652A,h2,Gabriel,h1,caterpillar,Caterpillar,include,day
From: https://blog.51cto.com/u_15834522/5766254

相关文章