一名苦逼的OIer,想成为ACMer

Iowa_Battleship

洛谷1033 自由落体

原题链接

本是道水题,但是这题目讲的太不清楚了。。
简单说下几个点:
这个小车实际上就是块平面,也就是说两边是没有挡板的,即小车在行驶中前面或尾部遇到了小球,也是算接到小球的。
而题目中的距离小车\(\leqslant 10 ^ {-4}\)的时候就算接到小球,这个距离是小球和小车的水平距离。

先推出小球落到\([H - K, H]\)之间的时候所用的时间:

\[H - K \leqslant \dfrac{1}{2} g t ^ 2 \leqslant H \]

\[\Rightarrow \sqrt{\dfrac{2(H - K)}{g}} \leqslant t \leqslant \sqrt{\dfrac{2H}{g}} \]

然后就可以计算出小车在这段时间的坐标,从而知道在水平上小球落到哪个区间可以被小车接住,注意考虑小车长度。设\(eps = 10 ^ {-4}\)

\[x_l = S - \sqrt{\dfrac{2H}{g}} \times V - eps \]

\[x_r = S - \sqrt{\dfrac{2(H - K)}{g}} \times V + L + eps \]

所以所有在\([x_l, x_r]\)之间的小球都可以被接住,可以直接算出在这个区间内能被接住的左右两端的小球。
注意\(x_l\)\(0\)\(\max\)\(x_r\)\(n - 1\)\(\min\)
最后的答案就是\(\max\{ \left\lfloor x_l \right\rfloor - \left\lceil x_r \right\rceil + 1, 0 \}\)

#include<cstdio>
#include<cmath>
using namespace std;
const double eps = 1e-4;
inline double maxn(double x, double y) { return x > y ? x : y; }
inline double minn(double x, double y) { return x < y ? x : y; }
int main()
{
	double H, S, V, L, K, l, r;
	int n;
	scanf("%lf%lf%lf%lf%lf%d", &H, &S, &V, &L, &K, &n);
	l = maxn(0, S - sqrt(H / 5) * V - eps);
	r = minn(n - 1, S - sqrt((H - K) / 5) * V + L + eps);
	printf("%d", (int)maxn((int)r - (int)ceil(l) + 1, 0));
	return 0;
}

posted on 2018-12-18 20:36  Iowa_Battleship  阅读(150)  评论(0编辑  收藏  举报

导航