题解 AT784 【直訴】

· · 题解

平面内求三角形面积公式如下:

((x1y2-x2y1)+(x2y3-x3y2)+(x3y1-x1y3))/2

这个公式必须要将点按顺序排列,但是我们可以不排列,当结果小于0的时候,直接输出相反数

#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    double x1,y1,x2,y2,x3,y3;
    scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3);
    double sum=((x1*y2-x2*y1)+(x2*y3-x3*y2)+(x3*y1-x1*y3))/2;
    if(sum>0) printf("%.1lf",sum);
    else printf("%.1lf",-sum);
    return 0;
}