码迷,mamicode.com
首页 > 其他好文 > 详细

LightOJ 1305 - Area of a Parallelogram(数学啊 )

时间:2015-03-29 10:56:28      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:lightoj   数学   

题目链接: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

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.

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

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(数学啊 )

标签:lightoj   数学   

原文地址:http://blog.csdn.net/u012860063/article/details/44724573

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!