LightOJ 1305 - Area of a Parallelogram(數學啊 )

來源:互聯網
上載者:User

標籤: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;}/*30 0 10 0 10 100 0 10 0 10 -20-12 -10 21 21 1 40*/

LightOJ 1305 - Area of a Parallelogram(數學啊 )

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.