HDU 4458 Shoot The airplane (calculates whether the geometric judgment point is within the N-side shape)

Source: Internet
Author: User
Tags acos

Shoot the airplane

Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 1037 Accepted Submission (s): 175


Problem Descriptionxxx is playing an interesting game which are based on a 2D plane. In this game, he's required to shoot an airplane. The airplane flies horizontally. The shape of it can be regarded as a simple polygon. The Player has to shoot on point (0, 0) upward vertically. Because the bullet is very small, it can be regarded as a point. The airplane is hits only if the bullet goes into the airplane. The airplane is not a hit if the bullet only touches the edge of the airplane. The gravity should be considered. The acceleration of gravity are G and its direction are downward vertically. The speed of the bullet is change during flying. But the speed of airplane was constant because it has engines. XXX wants to know the time it takes the bullet to hit the airplane after shooting.

Inputthere is multiple cases.
In each case, there is three integers V ( -10<= v <=), B (1 <= b <=), g (0 <= G <=) in the Firs T line. v denotes the speed of airplane. The flying direction is a from-left-to-right if-V is-positive and the direction-is-from-right-to-left if-V is negative. b denotes the initial speed of bullet. G is the acceleration of gravity. Then the input would describe the position of the airplane when XXX shoots. In the second line, there is one integer n (3 <= n <=) which represents the number of vertexes of the airplane (p Olygon). In each of the next n lines, there is integers x ( -100 <= x <=), y (0 <y<=) which give the Positi On the a vertex in order. There is a blank line after each case. The input ends with 0 0 0.

Outputif the airplane is hit and then output the time it takes the bullet to hits it after shooting on one line. The answer should is rounded to 2 digits after decimal point. If the airplane is not hit and then output "miss!" on one line.

Sample Input-10 10 296 910 910 1625 1625 2010 2010 276 27-10 18-10 10 296 910 910 1620 1620 2010 2010 276 27-10 180 0 0

Sample output2.00miss!

Source, Asia Hangzhou regional Contest

Main topic:

The title means, give you a two-dimensional plan, then, at (0,0) point there is a cannon, there is an n-shaped plane, asked you whether it is possible that the shell hit the plane. Aircraft with V=v0 do uniform motion, shells are the initial velocity of B, the acceleration of gravity g of the upper parabolic motion .... If you can hit the plane, it will output at a certain moment.

Problem Solving Ideas:

This problem at the time of the live game a out of the people are not many, it may be because of the accuracy problem, but, to tell the truth, the problem is not very difficult, if considering the relative coordinate changes of thought, it is easy to write out,

We assume that the plane is stationary, so the flight curve of the missile is an object similar to the flat-throw motion x=-v*t,y=0.5*g*t*t;

The point within the polygon is judged by the LRJ template.

Code:

# include<cstdio># include<iostream># include<vector># include<cmath>using namespace std;    Const double Pi=acos ( -1.0); const double Eps=1e-10;int dcmp (double x) {if (Fabs (x) <eps) return 0; return x<0?-1:1;}    struct point{double x, y;    Point () {} A (double x,double y): x (x), Y (y) {} point operator+ (const point&p) {return point (X+P.X,Y+P.Y);}    Point operator-(const point&p) {return point (X-P.X,Y-P.Y);}    Point operator* (double p) {return point (x*p,y*p);} Point operator/(double p) {return point (x/p,y/p);}}; typedef point Vector;double Dot (Vector a,vector b) {return a.x*b.x+a.y*b.y;} Double Cross (Vector A,vector b) {return a.x*b.y-a.y*b.x;} Double Length (Vector a) {return sqrt (Dot (a,a));} Double Angle (Vector A,vector b) {return ACOs (Dot (b)/length (a)/length (b));    BOOL Onsegment (point p,point a,point b) {if (dcmp (p-a,p-b))) return 0; Return dcmp (a.x-p.x) *dcmp (b.x-p.x) <=0&&dcmp (a.y-p.y) *dcmp (B.Y-P.Y) <=0;} typedef vector<point> Polygon;int Ispointinpolygon (Point P,polygon poly) {int wn=0;    int n=poly.size ();        for (int i=0;i<n;i++) {if (Onsegment (p,poly[i],poly[(i+1)%n])) return 0;        int k=dcmp (Cross (poly[(i+1)%n]-poly[i],p-poly[i]));        int d1=dcmp (POLY[I].Y-P.Y);        int d2=dcmp (poly[(i+1)%n].y-p.y);        if (k>0&&d1<=0&&d2>0) wn++;    if (k<0&&d2<=0&&d1>0) wn--; } return WN;    int main (void) {int n;    Double v,b,g;        while (scanf ("%lf%lf%lf", &v,&b,&g)!=eof) {if (v==0&&b==0&&g==0) break;        scanf ("%d", &n);        Polygon p;        Double max_y = 0.0,x,y;            for (int i = 0;i < n;i++) {scanf ("%lf%lf", &x,&y);            Max_y =max (max_y,y);        P.push_back (Point (x, y));        } int ok=0;        Double t=dcmp (g)? 2.0*b/g:max_y/b; for (Double t = 0.0;t <= t;t + = 0.001) {Point tmp (-v*t,B*T-0.5*G*T*T);                if (Ispointinpolygon (tmp,p)) {printf ("%.2lf\n", t);                ok=1;            Break    }} if (!ok) puts ("miss!"); }}

  

HDU 4458 Shoot The airplane (calculates whether the geometric judgment point is within the N-side shape)

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.