# BZOJ 2618: [Cqoi2006]凸多边形 半平面交

## 2618: [Cqoi2006]凸多边形

Time Limit: 5 Sec  Memory Limit: 128 MB
Submit: 2141  Solved: 1051
[Submit][Status][Discuss]

## Output

输出文件仅包含一个实数，表示相交部分的面积，保留三位小数。

2
6
-2 0
-1 -2
1 -2
2 0
1 2
-1 2
4
0 -3
1 -1
2 2
-1 0

5.233

## HINT

100%的数据满足：2<=n<=10，3<=mi<=50，每维坐标为[-1000,1000]内的整数

bzoj的板子题

#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<string>
#include<bitset>
#include<queue>
#include<set>
#include<map>
using namespace std;

typedef double db;
typedef long long ll;

{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
void print(int x)
{if(x<0)putchar('-'),x=-x;if(x>=10)print(x/10);putchar(x%10+'0');}

const int N=510;
const db eps=1e-8;

struct point
{
db x,y;

friend point operator +(const point &a,const point &b)
{return (point){a.x+b.x,a.y+b.y};}

friend point operator -(const point &a,const point &b)
{return (point){a.x-b.x,a.y-b.y};}

friend db dis(const point &a,const point &b)
{
point tmp(a-b);
return sqrt(tmp.x*tmp.x+tmp.y*tmp.y);
}

friend db cross(const point &x,const point &y,const point &bas)
{
point a(x-bas),b(y-bas);
return a.x*b.y-a.y*b.x;
}
}p[N],st[N];

struct segment
{
point X,Y;db angle;

friend bool operator <(const segment &a,const segment &b)
{
if(abs(a.angle-b.angle)<eps) return cross(a.Y,b.X,a.X)<0;
return a.angle<b.angle;
}

friend point get_insert(const segment &a,const segment &b)
{
db S[2];
point res;
S[0]=cross(a.X,a.Y,b.X),
S[1]=cross(a.Y,a.X,b.Y);
res.x=(b.X.x*S[1]+b.Y.x*S[0])/(S[0]+S[1]),
res.y=(b.X.y*S[1]+b.Y.y*S[0])/(S[0]+S[1]);
return res;
}

}seg[N];

int seg_cnt;

inline void add_seg(const point &a,const point &b)
{
seg[++seg_cnt].X=a,seg[seg_cnt].Y=b;
seg[seg_cnt].angle=atan2(b.y-a.y,b.x-a.x);
}

bool check(int a,int b,int c)
{
point tmp(get_insert(seg[a],seg[b]));
return cross(seg[c].Y,tmp,seg[c].X)<0;
}

int q[N],top;

void hpi()
{
sort(seg+1,seg+1+seg_cnt);
for(i=2;i<=seg_cnt;++i)
if(seg[i].angle-seg[tot].angle>eps)
seg[++tot]=seg[i];
q[0]=1,q[1]=2;
for(i=3;i<=tot;++i)
{
q[tail++]=i;
}
st[++top]=get_insert(seg[q[i]],seg[q[i+1]]);
}

void solve()
{
db S(0);
register int i;
for(i=2;i<top;++i)
S+=cross(st[i],st[i+1],st[1]);
printf("%.3lf\n",S*0.5);
}

int main()
{
while(T--)
{