Codeforces 652A Gabriel and Caterpillar【水题】

这道题目描述了一只魔法森林中的毛毛虫,它每天白天向上爬a厘米,晚上向下滑b厘米,目标是达到比起点高h2-h1厘米的苹果位置。一位名叫Gabriel的学生在下午2点后才能观察到毛毛虫,求他需要等待多少天才能看到毛毛虫摘到苹果。题目提供了一些示例输入和输出,包括无法达到苹果的情况。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目链接:Codeforces 652A Gabriel and Caterpillar

A. Gabriel and Caterpillar
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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 by b 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 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
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.

题意:毛毛虫爬树摘苹果,白天一小时爬 a cm,晚上每小时掉bcm,奇葩的是。有个人想看毛毛虫摘苹果,而且只能在每天下午2点之后才可以看到,问需要等待多少天可以看到毛毛虫摘苹果。

狗血题目,欺负我的理解能力。

AC 代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#define PI acos(-1.0)
#define CLR(a, b) memset(a, (b), sizeof(a))
#define fi first
#define se second
#define ll o<<1
#define rr o<<1|1
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const int MAXN = 1e6 + 10000;
const int pN = 1e6;// <= 10^7
const int INF = 0x3f3f3f3f;
const int MOD = 2009;
void add(LL &x, LL y) { x += y; x %= MOD; }
int main()
{
    int h1, h2, a, b; cin >> h1 >> h2 >> a >> b;
    if(a <= b) {
        if(h1 + 8 * a < h2) {
            cout << -1 << endl;
            return 0;
        }
    }
    if(h1 + 8 * a >= h2) {
        cout << 0 << endl;
        return 0;
    }
    int h = h2 - h1 - 8 * a;
    int d = 12 * (a - b);
    int ans = h / d;
    if(h % d) ans++;
    cout << ans << endl;
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值