POJ 3130 || How I Mathematician Wonder What You Are!

The mathematical definition of a star shape is as follows: A planar shape F is star-shaped if and only if there is a point C ∈ F such that, for any point P ∈ F, the line segment CP is contained in F. Such a point C is called a center of F. To get accustomed to the definition let’s see some examples below.

半平面交裸题,我已经不想再多说什么了。。秒A。。。

#include
#include
#include
#include
using namespace std;
const double eps = 1e-8;
struct Point{
    double x,y;
    Point(double xx=0.0,double yy=0.0):x(xx),y(yy){}
    Point operator - (const Point &b)const{
        return Point(x-b.x,y-b.y);
    }
    Point operator +(const Point &b)const{
        return Point(x+b.x,y+b.y);
    }
    Point operator /(const double &b)const{
        return Point(x/b,y/b);
    }
    Point operator *(const double &b)const{
        return Point(x*b,y*b);
    }
    double operator ^(const Point &b)const{
        return x*b.y-y*b.x;
    }
}p[150];
typedef Point myvec;
double cross(myvec a,myvec b){
    return a^b;
}
struct Line{
    Point p;
    myvec v;
    double ang;
    Line(){}
    Line( Point pp,myvec vv):p(pp),v(vv)
    {
        ang = atan2(v.y,v.x);
    }
    bool operator < (const Line &l)const{
        return ang < l.ang;
    }

}L[150];
//点p在有向直线L的左边(线上不算)
bool on_left( Line l,Point p){
    return cross(l.v,p-l.p)>0;
}
//直线交点 假设交点唯一存在
Point get_inter_section(Line a,Line b){
    myvec u = a.p - b. p;
    double t = cross(b.v,u)/cross(a.v,b.v);
    return a.p+a.v*t;

}
int half_plane_inter_section(Line *L,int n,Point *poly){
    sort(L,L+n);//级角排序
    int fir,lst;//双向队列的第一个元素和最后一个元素的下标
    Point *p = new Point[n];//p[i] 为q[i]和q[i+1]的交点
    Line *q = new Line[n];//双端队列
    q[ fir = lst = 0 ] = L[0];//双端队列初始化为只有一个半平面的L[0]
    for( int i =1; i 


你可能感兴趣的:(计算几何,POJ,3130,How,I,Mathematician)