【CodeForces】[652A]Gabriel and Caterpillar

这里写图片描述

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

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

#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
");
        else {
            if(a<=b)
                printf("-1
");
            else {
                int res=0;
                while(h1<h2) {
                    h1-=b*12;
                    h1+=a*12;
                    res++;
                }
                printf("%d
",res);
            }
        }
    }
    return 0;
}

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

原文地址:https://www.cnblogs.com/BoilTask/p/12569593.html