西南科技大学OJ题 Jack's problem 0203

Jack's problem

 1000(ms)

 65535(kb)

 1978 / 6036

One day, Jack’s mother make a piece of pizza for him and his father. And Jack think everyone should get 1/3 of the pizza so that everyone get the same. Now he choose three points on the pizza and he want to know the area of this triangle.

输入

There are several test cases. Each case contains six integers x1,y1,x2,y2,x3,y3.
You can assume three points will not be on one line.

输出

Output the area of the triangle formed by point (x1,y1),(x2,y2),(x3,y3) with exactly one digit after the decimal point.

样例输入

0 0 1 1 1 0
0 0 2 2 2 0

样例输出

0.5
2.0

#include<stdio.h>
#include<math.h>
int main()
{
    int x1,y1,x2,y2,x3,y3;
    while(scanf("%d %d %d %d %d %d",&x1,&y1,&x2,&y2,&x3,&y3)!=EOF)
    {
        float a,b,c,p,s;
        a=sqrt(pow((y2-y1),2)+pow((x2-x1),2));
        b=sqrt(pow((y3-y1),2)+pow((x3-x1),2));
        c=sqrt(pow((y2-y3),2)+pow((x2-x3),2));
        p=(a+b+c)/2;
        s=sqrt(p*(p-a)*(p-b)*(p-c));
        printf("%.1f\n",s);
    }
}

猜你喜欢

转载自blog.csdn.net/qq_40593308/article/details/84500022
今日推荐