UVA 11800 determine the Shape

Source: Internet
Author: User

Vjudge on the topic Link: Determine the Shape

The second way alone a out of the computational geometry water problem, test instructions is to give you four points, let you judge what kind of quadrilateral it is: square, rectangle, diamond, parallelogram, trapezoidal or ordinary quadrilateral.

According to the characteristics of each quadrilateral layer of judgment on the line, but the problem of the relative position of the four points (point and point is adjacent or relative uncertainty), so need to enumerate all kinds of situations, fortunately 4 points altogether only 3 different cases: ABCD, ABDC, ACBD draw a picture can be at a glance, Next is the code, but because of some of the details of the problem I still debugging a while O (╯-╰) o

1#include <cstdio>2#include <cstring>3#include <cmath>4#include <algorithm>5 using namespacestd;6 7 structVector {8     Doublex, y;9Vector (Doublex =0,Doubley =0): X (x), Y (y) {}Ten     voidReadint () { One         intx, y; Ascanf"%d%d",&x,&y); -          This->x =x; -          This->y =y; the     } -Vectoroperator+ (ConstVector &b)Const { -         returnVector (x + b.x, y +b.y); -     } +Vectoroperator- (ConstVector &b)Const { -         returnVector (x-b.x, Y-b.y); +     } AVectoroperator* (DoublePConst { at         returnVector (x * p, Y *p); -     } -Vectoroperator/ (DoublePConst { -         returnVector (x/p, Y/p); -     } - }; in  - typedef Vector Point; totypedefConstpoint&CPoint; +typedefConstvector&Cvector; -  theVectoroperator* (DoublePConstVector &a) { *     returnAp; $ }Panax Notoginseng  - DoubleDot (Cvector A, cvector b) { the     returna.x * b.x + a.y *b.y; + } A  the DoubleLength (Cvector a) { +     returnsqrt (dot (a,a)); - } $  $ DoubleCross (Cvector A, cvector b) { -     returna.x * B.Y-A.Y *b.x; - } the  - Const DoubleEPS = 1e-Ten;Wuyi intDCMP (Doublex) { the     returnFabs (x) < EPS?0: (X <0? -1:1); - } Wu  - BOOL operator==(CPoint A, CPoint b) { About     returnDCMP (a.x-b.x) = =0&& dcmp (a.y-b.y) = =0; $ } -  - Const Chars[8][ -] = {"Ordinary quadrilateral","Trapezium","Parallelogram", -                 "Rhombus","Rectangle","Square" }; A  + intjudge (CPoint A, CPoint B, CPoint C, CPoint d) { the     if(DCMP (A-B, c-d) = =0) { -         if(DCMP (Cross (b-c, a-d)) = =0) { $             if(dcmp (Length (b-a)-Length (d-a)) = =0) { the                 if(DCMP (dot (b-a, d-a)) = =0)return 5; the                 Else    return 3; the             } the             Else if(DCMP (dot (b-a, d-a)) = =0)return 4; -             Else    return 2; in         } the         Else   return 1; the     } About     Else if(DCMP (Cross (b-c, a-d)) = =0)return 1; the     Else    return 0; the } the  + intMain () { -     intT,case =0; the Point a,b,c,d;Bayiscanf"%d",&t); the      while(t--) { the a.readint (); - b.readint (); - c.readint (); the d.readint (); theprintf"Case %d:",++Case ); the         intAns =0; theAns =Max (ans, Judge (a,b,c,d)); -Ans =Max (ans, Judge (a,b,d,c)); theAns =Max (ans, Judge (a,c,b,d)); theprintf"%s\n", S[ans]); the     }94     return 0; the}
View Code

Calculate the geometry, or it's interesting ...

UVA 11800 determine the 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.