【CodeForces】[652A]Gabriel and Caterpillar

Problem Description

Loading...

Problem Analysis

On day 0, it crawls for 8 hours during the day
after that, 12 hours during the day and 12 hours at night
So…

Exclude the special cases
then just simulate it
Also, the problem statement says
that the caterpillar can go underground (negative values are allowed)

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include<stdio.h>
int main() {
	int h1,h2;
	while(scanf("%d %d",&h1,&h2)!=EOF) {
		int a,b;
		scanf("%d %d",&a,&b);
		h1+=a*8;
		if(h1>=h2)
			printf("0\n");
		else {
			if(a<=b)
				printf("-1\n");
			else {
				int res=0;
				while(h1<h2) {
					h1-=b*12;
					h1+=a*12;
					res++;
				}
				printf("%d\n",res);
			}
		}
	}
	return 0;
}

Problem link:【CodeForces】[652A]Gabriel and Caterpillar

This post is licensed under CC BY-NC-SA 4.0. If it helped, or if you have anything to say, the comment box below is open.
Page views —
Unique visitors —

Loading...