题目链接:http://lightoj.com/volume_showproblem.php?problem=1305
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 ABCDshould be same as in the picture.
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 andC will not be collinear.
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 |
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 |
求平行四边形的D点和面积!
代码如下:
#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;
}
/*
3
0 0 10 0 10 10
0 0 10 0 10 -20
-12 -10 21 21 1 40
*/
LightOJ 1305 - Area of a Parallelogram(数学啊 )
原文地址:http://blog.csdn.net/u012860063/article/details/44724573