题目地址:http://acm.nyist.net/JudgeOnline/problem.php?pid=67
思路:任意2边向量的叉积的绝对值的1/2即为三角形的面积
AC代码:
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <queue> #include <stack> #include <map> #include <cstring> #include <climits> #include <cmath> #include <cctype> const int inf = 0x7f7f7f7f;//2139062143 typedef long long ll; using namespace std; int main() { double x1,x2,x3,y1,y2,y3; while(scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3)) { if(x1+x2+x3+y1+y2+y3 == 0) break; double sum = fabs((x2-x1)*(y3-y1)-(x3-x1)*(y2-y1)) / 2; printf("%.1lf\n",sum); } return 0; }