【SSL_1715】计算面积

在这里插入图片描述

思路:

叉积模板

c o d e code code

#include<iostream>
#include<cstdio>

using namespace std;

int t;
int x, y, x1, y1, x2, y2;
double ans;

double js(int x, int y, int x1, int y1)
{
    
    
	return x*y1-x1*y;
}

int main()
{
    
    
	scanf("%d", &t);
	while(t--)
	{
    
    
		scanf("%d%d%d%d%d%d", &x, &y, &x1, &y1, &x2, &y2);
		double s1=js(x1-x, y1-y, x2-x, y2-y);
		double s2=js(x-x1, y-y1, x2-x1, y2-y1);
		double s3=js(x-x2, y-y2, x1-x2, y1-y2);
		ans=max(s1, max(s2, s3));
		if(ans==0)
			printf("Error\n");
		else printf("%.1lf\n", ans);
		ans=0;
	}
	return 0;
}

おすすめ

転載: blog.csdn.net/liuziha/article/details/122527673