半平面交。poj2451

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
struct pointt
{
	double x, y;
	pointt(double x, double y) :x(x), y(y)
	{}
	pointt()
	{}
};
pointt operator+(pointt a, pointt b)
{
	return pointt(a.x + b.x, b.y + a.y);
}
pointt operator-(pointt a, pointt b)
{
	return pointt(a.x - b.x, a.y - b.y);
}
pointt operator*(pointt a, double t)
{
	return pointt(a.x*t, a.y*t);
}
double operator*(pointt a, pointt b)
{
	return a.x*b.x + a.y*b.y;
}
double dot(pointt a, pointt b)
{
	return a.x*b.y - a.y*b.x;
}
double length(pointt a)
{
	return sqrt(a*a);
}
struct linee
{
	pointt p1, vec, verti;
	double arc;
	linee(pointt a, pointt b) :p1(a), vec(b - a)
	{
		arc = atan2(vec.y, vec.x);
		double l = length(vec);
		verti.x = -vec.y / l; verti.y = vec.x / l;
	}
	linee()
	{}
	bool operator<(linee b)
	{
		return arc < b.arc;
	}
};
bool isonleft(pointt a, linee b)
{
	pointt c = a - b.p1;
	return dot(c, b.vec) < 0;
}
pointt inter(linee a, linee b)
{
	pointt c = a.p1 - b.p1;
	if (fabs(dot(b.vec, a.vec)) < 1e-10)return pointt(1000000000, 1000000000);
	double t = dot(c, b.vec) / dot(b.vec, a.vec);
	return a.p1 + a.vec*t;
}
linee realline[20050];
linee line[200550];
pointt point[20050];
double ans;
int edgetot;
void halfmat(linee *l, int n)
{
	sort(l, l + n);
	int first = 0; int  last = 0;
	realline[first] = l[0];
	for (int i = 1; i < n; i++)
	{
		while ((last - first)>0 && !isonleft(point[last - 1], l[i]))last--;
		while ((last - first) > 0 && !isonleft(point[first], l[i]))first++;
		if (fabs(dot(l[i].vec, realline[last].vec)) < 1e-10)continue;
		realline[++last] = l[i];
		if (last - first > 0)point[last - 1] = inter(realline[last], realline[last - 1]);
	}
	while ((last - first) > 0 && !isonleft(point[last - 1], realline[first]))last--;
	if ((last - first) > 0)point[last] = inter(realline[first], realline[last]);
	if ((last - first) <= 1)
		return;
	for (int i = first + 2; i <= last; i++)
	{
		ans += fabs(dot(point[i] - point[first], point[i - 1] - point[first]));
	}
	ans /= 2;

}
int main()
{
	int n;
	scanf("%d", &n);
	line[edgetot++] = linee(pointt(0, 0), pointt(10000, 0)); line[edgetot++] = linee(pointt(10000, 0), pointt(10000, 10000));
	line[edgetot++] = linee(pointt(10000, 10000), pointt(0, 10000)); line[edgetot++] = linee(pointt(0, 10000), pointt(0, 0));
		for (int i = 0; i < n; i++)
		{
			pointt a, b;
			scanf("%lf%lf%lf%lf", &a.x, &a.y, &b.x, &b.y);
			line[edgetot++] = linee(a, b);
		}
		halfmat(line,edgetot);
		printf("%.1lf\n",ans);
		return 0;
}



终于过了。。。。。23333333

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值