CF652A Gabriel and Caterpillar

CF652A Gabriel and Caterpillar

洛谷传送门

题意翻译

9年级的学生加百利在树上高度为h1的地方发现了一只毛毛虫正向着高度为h2的苹果进发。它在白天每小时上升a厘米,晚上每小时下掉b厘米。可以认为白天从10点开始至22点结束,黑夜从22点开始至次日10点结束。Gabriel是在下课后看到毛毛虫。加百利每天14点下课,他想知道,几天后他来恰好能看到毛毛虫正在吃苹果? fixed:Gabriel是在下课后看到毛毛虫的 ——by:沉迷学习的YZM


题解:

模拟即可。看起来像小学奥数,其实连小学奥数都不是。因为一般人应该都知道速度差这个概念。

代码:

#include<iostream>
using namespace std;
int h1,h2,a,b;
int main()
{
	cin>>h1>>h2>>a>>b;
	if(a <= b)
		if (h1+8*a < h2)
		{
			puts("-1");
			return 0;
		}
	if(h1+8*a >= h2) 
	{
		puts("0");
		return 0;
	}
	int h=h2-h1-8*a;
	int d=(a-b)*12;
	int ans = h/d;
	if(h%d)
		ans++;
	printf("%d
",ans);
	return 0;
}
原文地址:https://www.cnblogs.com/fusiwei/p/14037780.html