NYOJ 67 三角形面积

原题链接

已知三角形PMN三个顶点坐标为(x1, y1) (x2, y2) (x3, y3),求该三角形的面积S


S = |(x1y2+y1x3+x2y3-x1y3-y1x2-y2x3)| / 2

知道这个公式就好办了。

附ac代码:

#include <stdio.h>
#include <stdlib.h>

int main(){
	int x1, y1, x2, y2, x3, y3;
	while(scanf("%d%d%d%d%d%d", &x1, &y1, &x2, &y2, &x3, &y3),
			x1 || y1 || x2 || y2 || x3 || y3)
		printf("%.1lf\n", abs(x1*y2 + y1*x3 + x2*y3 - x1*y3 - y1*x2 - x3*y2) / 2.0);
	return 0;
}


posted on 2014-02-11 17:55  长木Qiu  阅读(137)  评论(0编辑  收藏  举报