公式自己推啦......
AC代码如下:
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
typedef struct{
double x, y;
}Point;
int main(){
Point p[4];
int T;
double a, b, c, m, n;
double area;
cin >> T;
while( T-- ){
cin >> p[1].x >> p[1].y;
cin >> p[2].x >> p[2].y;
cin >> p[3].x >> p[3].y;
for( int i = 3; i > 1; i-- ){
for( int j = 1; j < i; j++ ){
if( p[j].x > p[j+1].x ){
Point temp;
temp = p[j];
p[j] = p[j+1];
p[j+1] = temp;
}
}
}
double temp1, temp2;
temp1 = ( p[1].y - p[2].y ) / ( p[1].x - p[2].x );
temp2 = ( p[2].y - p[3].y ) / ( p[2].x - p[3].x );
a = ( temp1 - temp2 ) / ( p[1].x - p[3].x );
b = temp1 - a * ( p[1].x + p[2].x );
c = p[1].y - a * p[1].x * p[1].x - b * p[1].x;
m = ( p[3].y - p[1].y ) / ( p[3].x - p[1].x );
n = p[1].y - m * p[1].x;
temp1 = a * ( pow( p[3].x, 3 ) - pow( p[1].x, 3 ) ) / 3.0 + b * ( pow( p[3].x, 2 ) - pow( p[1].x, 2 ) ) / 2.0 + c * ( pow( p[3].x, 1 ) - pow( p[1].x, 1 ) );
temp2 = m * ( pow( p[3].x, 2 ) - pow( p[1].x, 2 ) ) / 2.0 + n * ( pow( p[3].x, 1 ) - pow( p[1].x, 1 ) );
area = temp1 - temp2;
printf( "%.2lf\n", area );
}
return 0;
}