Area of a Parallelogram

http://acm.hust.edu.cn:8080/judge/contest/view.action?cid=8086#problem/H

 
Description

A parallelogram is a quadrilateral with two pairs of parallel sides. See the picture below:

 

Fig: a parallelogram

Now you are 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 ABCD should be 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 coordinate of A, (Bx, By) denotes the coordinate of B and (Cx, Cy) denotes the coordinate of C. Value of any coordinate lies in the range [-1000, 1000]. And you can assume that A, B and C will not be collinear.

Output

For each case, print the case number and three integers where the first two should be the coordinate of D and the third one should be the area of the parallelogram.

Sample Input

3

0 0 10 0 10 10

0 0 10 0 10 -20

-12 -10 21 21 1 40

Sample Output

Case 1: 0 10 100

Case 2: 0 -20 200

Case 3: -32 9 1247

方法二
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std ;

typedef struct Coord{
    int x , y ;
} Coord ;

Coord c[4] ;

int CalcuArea()
{
    double lab = sqrt( (c[0].x-c[1].x)*(c[0].x-c[1].x)  + (c[0].y-c[1].y)*(c[0].y-c[1].y) ) ;
    double lad = sqrt( (c[0].x-c[3].x)*(c[0].x-c[3].x)  + (c[0].y-c[3].y)*(c[0].y-c[3].y) ) ;
    double d = fabs( (c[3].x-c[0].x)*(c[1].x-c[0].x) + (c[3].y-c[0].y)*(c[1].y-c[0].y) ) / lab ;
    double h = sqrt( lad*lad - d*d ) ;
    int ar = h * lab+0.5 ;
    return ar ;
}

int main()
{
    int T , i , ar , n ;
    scanf("%d", &T ) ;
    n = T ;
    while(T -- )
    {
        for(i = 0 ; i < 3 ; i ++ ) scanf("%d %d" , &c[i].x , &c[i].y ) ;
        c[3].x = c[2].x - c[1].x + c[0].x ;
        c[3].y = c[2].y - c[1].y + c[0].y ;
        ar = CalcuArea() ;
        printf("Case %d: %d %d %d\n", n - T , c[3].x , c[3].y , ar) ;
    }
    return 0 ;
} 
方法一
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 using namespace std ;
 5 
 6 typedef struct Coord{
 7     int x , y ;
 8 } Coord ;
 9 
10 Coord c[4] ;
11 
12 int CalcuArea()
13 {
14     int lab =abs((c[3].x-c[0].x)*(c[1].y-c[0].y)-(c[3].y-c[0].y)*(c[1].x-c[0].x));
15     return lab;
16 }
17 
18 int main()
19 {
20     int T , i , ar , n ;
21     scanf("%d", &T ) ;
22     n = T ;
23     while(T -- )
24     {
25         for(i = 0 ; i < 3 ; i ++ ) scanf("%d %d" , &c[i].x , &c[i].y ) ;
26         c[3].x = c[2].x - c[1].x + c[0].x ;
27         c[3].y = c[2].y - c[1].y + c[0].y ;
28         ar = CalcuArea() ;
29         printf("Case %d: %d %d %d\n", n - T , c[3].x , c[3].y , ar) ;
30     }
31     return 0 ;
32 } 
原文地址:https://www.cnblogs.com/wujianwei/p/2497277.html