ZSOI2013 蓄养 暴力

如果没看数据范围还以为是一道旋转卡壳

然而实际上只有100.求面积标程用了海伦公式,实际上叉积就可以了

注意答案不能为0

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#define LL long long
#define fo(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
#define N 105
struct point
{
	double x,y;
}d[N];
double inf=0.000000001;
int n;

double CJ(int x,int y,int k)
{
	point xy,yk;
	xy.x=d[x].x-d[y].x;
	xy.y=d[x].y-d[y].y;
	yk.x=d[y].x-d[k].x;
	yk.y=d[y].y-d[k].y;
	return (double)fabs((double)xy.x*yk.y-(double)yk.x*xy.y);
}

bool GX(int x,int y,int k)
{
	point xy,yk;
	xy.x=d[x].x-d[y].x;
	xy.y=d[x].y-d[y].y;
	yk.x=d[y].x-d[k].x;
	yk.y=d[y].y-d[k].y;
	if((double)((double)xy.y/xy.x)==((double)yk.y/yk.x))return 1;
	else return 0;
}

int main()
{
	freopen("herding.in","r",stdin);
	freopen("herding.out","w",stdout);
	scanf("%d",&n);
	double ans=-1000;
	fo(i,1,n)scanf("%lf%lf",&d[i].x,&d[i].y);
	fo(i,1,n)
	{
		fo(j,1,n)
		if(i!=j)
		{
			fo(k,1,n)
			if(j!=k&&i!=k)
			{
				double ret=CJ(i,j,k);
				if(ret<inf)continue;
//				cout<<ret<<' '<<ans<<endl;
				if(ans<0.00||(double)ret-ans<(double)inf)
				{
					ans=ret;
				}
			}
		}
	}
	ans=(double)((double)ans*(double)0.5);
	if(ans<inf)puts("Impossible");else printf("%.2lf",ans);
	return 0;
}


你可能感兴趣的:(暴力)