Title Link: http://lightoj.com/volume_showproblem.php?problem=1305
A parallelogram is a quadrilateral with the pairs of parallel sides. See the picture below:
Fig:a Parallelogram
Now is given the co ordinates of A, B and C, you have to find the coordinates of D and the Area of the parallelogram. The orientation of ABCDshould is same as in the picture.
Input
Input starts with an integer T (≤1000), denoting the number of test cases.
Each case starts with a line containing six integers ax, ay, Bx, by, Cx, Cy where (ax, Ay) denotes the C Oordinate of A, (Bx, by) denotes the coordinate of B and (Cx, Cy) denotes the Coordina Te of C. Value of any coordinate lies in the range [ -1000, +]. And you can assume A, B and C would not be collinear.
Output
For each case, print the case number and three integers where the first and the should is the coordinate of D and T He third one should is the area of the parallelogram.
| Sample Input |
Output for Sample Input |
3 0 0 10 0 10 10 0 0 10) 0 10-20 -12-10 21 21 1 40 |
Case 1:0 10 100 Case 2:0-20 200 Case 3:-32 9 1247
|
Test Instructions:
Find the D-spot and the area of parallelogram!
The code is as follows:
#include <cstdio> #include <cmath> #include <cstring> #include <iostream> #include < algorithm>using namespace std;double dis (int x1, int y1, int x2, int y2) {return sqrt ((x1-x2) * (X1-X2) + (y1-y2) * (y1-y2 ));} int main () {int t; int cas = 0; scanf ("%d", &t); while (t--) {int Ax,ay, BX, by, CX, CY; int dx, DY; Double area; scanf ("%d%d%d%d%d%d", &ax,&ay,&bx,&by,&cx,&cy); int xx = Bx-ax; int yy = cy-by; DX = cx-xx; dy = ay + yy; Double dis_ad = dis (ax,ay,dx,dy); Double dis_db = dis (dx,dy,bx,by); Double dis_ab = dis (ax,ay,bx,by); Double CosA; if (((dis_ad) * (DIS_AD) + (dis_ab) * (dis_ab) = = (dis_db) * (dis_db))) {CosA = 0; } else CosA = (dis_ad*dis_ad+dis_ab*dis_ab-dis_db*dis_db)/(2*DIS_AD*DIS_AB); Double SinA = sqrt (1-cosa*cosa); Area = Dis_ad * Dis_ab * SinA; printf ("Case%D:%d%d%.0lf\n ", ++cas,dx,dy,area); } return 0;} /*30 0 10 0 10 100 0 10 0 10-20-12-10 21 21 1 40*/
Lightoj 1305-area of a parallelogram (mathematics AH)