Cdoj 27 Baseball Defense (baseball) Problem Solving report

Source: Internet
Author: User

Topic Link HTTP://ACM.UESTC.EDU.CN/#/PROBLEM/SHOW/27

This is a math problem, compared to the pit, it took me a few days

Formula pushed for a long time, because it looks like trouble, so put a few days do not bother to do ... After all summer vacation

The variable name given by the title is too sore, I'm making a new pact here.

The coordinates of the defender are \ ((x_0, y_0) \), Speed \ (v_0\)
The speed of rolling the earth is \ (v\), along the x-axis speed is \ (v_x\), y-axis sub-speed is \ (v_y\)
The landing point of the flying Ball is \ ((x, y) \), flight time \ (t\)

The difficulty lies in rolling the Earth, as long as an infield meets the ball or reaches the trajectory ahead of time.

I didn't ask for a bump in the infield, I thought it was in the infield, rolling the earth.

In this case, the subject becomes a two-time function in \ (\left[0, \frac{r}{\sqrt{x^2+y^2}}\right]\) There is no solution to the situation

If not in the infield is much simpler, only requires a two function in the \ ([0, +\infty) \) There is no solution can

The first flying ball, very simple, calculate the \ (\sqrt{(x-x_0) ^2+ (Y-Y_0) ^2}\) and \ (vt\) relationship can be

This is a simple relationship, I don't think I need an explanation.

Then to roll the Earth, to make the ball accessible, it requires the infield defender to run to the ball time \ (t\) meet the following conditions \[\sqrt{(V_XT-X_0) ^2+ (v_yt-y_0) ^2}\le v_0t\]

This is a two-time inequality about T, we combine both sides of the square and move the items together, and because \ (v_x^2+v_y^2=v^2\), we have: \[(v^2-v_0^2) t^2-2 (v_xx_0+v_yy_0) t+ (x_0^2+y_0^2) \le0\]

Very beautiful inequality, as long as the inequality in \ (t\in [0,\infty) \) has a solution can

When \ (V\ge v_0\), this is obviously a solution

When \ (v < v_0\), the function \ (f (t) = (v^2-v_0^2) t^2-2 (v_xx_0+v_yy_0) t+ (x_0^2+y_0^2) \) has a symmetric axis of \ (t_0=\frac{v_xx_0+v_yy_0}{v^2-v_ 0^2} > 0\)

So just need

\[
\begin{align*}
\delta&=4 (V_XX_0+V_YY_0) ^2-4 (v^2-v_0^2) (x_0^2+y_0^2) \ \
&=4 (v_x^2x_0^2+v_y^2y_0^2+2v_xv_yx_0y_0-v^2x_0^2-v^2y_0^2+v_0^2x_0^2+v_0^2y_0^2) \ \
&=4[v_0^2 (x_0^2+y_0^2)-v_y^2x_0^2+2v_xv_yx_0y_0-v_x^2y_0^2]\\
&=4[v_0^2 (x_0^2+y_0^2)-(V_YX_0-V_XY_0) ^2]\geq0
\end{align*}
\]

i.e. \ (v_0^2 (x_0^2+y_0^2) \geq (v_yx_0-v_xy_0) ^2\)

So in summary, as long as an infield defender satisfies \ (V\ge v_0\) or \ (v_0^2 (x_0^2+y_0^2) \geq (V_YX_0-V_XY_0) ^2\) The strike is out

So hit the code as follows

#include <cstdio> #include <cmath>using namespace std; #define EPS (1e-8) int N, M;int x[10], y[10], V[10];char b All;double XX, YY, T;int H, L, vv;double VX, Vy;bool safe;inline double Sqr (double x) {return x * x;}  int main () {while (scanf ("%d%d", &n, &m) && N && M) {for (int i = 0; i < N; ++i) scanf ("%d%d%d",  &x[i], &y[i], &v[i]); while (m--) {safe = true;while (Ball = GetChar ())! = ' F ' && ball! = ' G '); switch (ball) {case ' G ': scanf ("%d/%d%d", &h, &l, &AMP;VV), VX = VV * L/SQRT (SQR (h) + SQR (l)), VY = vv * H/SQRT (SQR (h) + SQR (l) ); for (int i = 0; i < N; ++i) if (Sqr (X[i]) + SQR (Y[i]) < () safe &= VV > V[i] && (SQR (x[i)) + SQR (y[ I])) * SQR (V[i]) < SQR (X[i] * vy-y[i] * VX); Break;case ' F ': scanf ("%lf%lf%lf", &xx, &yy, &t); for (int i = 0; i < N; ++i) Safe &= sqr (Xx-x[i]) + SQR (Yy-y[i]) > Sqr (v[i] * T); if (safe) puts ("safe"); Else puts ("out");}} return 0;}

Cdoj 27 Baseball Defense (baseball) Problem solving report

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.