【CodeForces】[652A]Gabriel and Caterpillar

文章字数:170

问题描述

问题分析

第0天 白天爬8小时
以后白天12小时 晚上12小时
所以……

把特殊情况排除在外
然后进行模拟就好了
而且题目说明了
虫子是可以进入地下的(可为负数)

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

题目地址:【CodeForces】[652A]Gabriel and Caterpillar

该内容采用 CC BY-NC-SA 4.0 许可协议。

如果对您有帮助或存在意见建议,欢迎在下方评论交流。

加载中...