King ' s sanctuaryTime limit:3000/1000ms (java/others) Memory limit:65535/65535kb (java/others)SubmitStatus
The king found his adherents were building four sanctuaries for him. He is interested about the positions of the sanctuaries and wants to know whether they would form a parallelogram, Rectang Le, diamond, square or anything else.
Input
The first line of the input is t T( 1≤T ≤ + 1≤t≤1000), which stands for the number of test cases you need to solve. Each case is contains four lines, and there is both integers in each line, which shows the position of the four sanctuaries. And it is guaranteed, the positions is given clockwise. And it's always a convex polygon, if you connect the four points clockwise.
Output
For every test case, should outputCase #t:
First, where t TIndicates the case number and counts from 1 1, then output the type of the quadrilateral.
Sample Input and output
Sample Input |
Sample Output |
50", "0", 02-10, one by one |
Case #1: parallelogramcase #2: rectanglecase #3: diamondcase #4: squarecase #5: Others |
Source
Sichuan State Programming Contest 2012
Original title Link: http://acm.uestc.edu.cn/#/problem/show/93
Test instructions: give you the coordinates of four points clockwise (clockwise) to determine if it is parallelogram, rectangle, diamond, square.
Geometry, it is sure to use the vector, the specific determination of the shape of the four-sided, you see the geometry of the first high school, specific judgments, look at the following picture.
AC Code:
#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <cmath >using namespace std;struct point{int x, y;} p[4];int main () {int T; int kase=0; cin>>t; while (t--) {for (int i=0; i<4; i++) {cin>>p[i].x>>p[i].y; } int px= (p[1].x-p[0].x); int py= (P[1].Y-P[0].Y); int qx= (p[2].x-p[3].x); int qy= (P[2].Y-P[3].Y); int rx= (p[2].x-p[1].x); int ry= (P[2].Y-P[1].Y); int tx=p[3].x-p[0].x; int ty=p[3].y-p[0].y; printf ("Case #%d:", ++kase); if (px==qx&&py==qy&&rx==tx&&ry==ty)//two pairs of edges are equal--parallelogram {if (px*rx+py*ry==0)//+ neighbor Edge---rectangle or square {if (px*px+py*py==rx*rx+ry*ry)//+ adjacent edge--square { cout<< "Square" <<endl; } else cout<< "Rectangle" <<endl The else if (px*px+py*py==rx*rx+ry*ry)//+ adjacent edges are not vertical but equal--diamond {cout<< "diamond" << ; Endl; } else//Parallelogram cout<< "Parallelogram" <<endl; } else cout<< "Others" <<endl; } return 0;}
Cdoj King's Sanctuary "judging quadrilateral shape"