hdu 1071 数学

公式自己推啦......

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;
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值