poj 1696 Space Ant 卷包裹法

题目地址:poj1696

首先好好研究卷包裹法的思路,发现每一plant一定是可以走到的。

这篇文章写的很好 这里

然后就是把这些点的标号存起来啦,因为不是求点的坐标,要存储原来的标号,所以弄了一个struct 作为映射原来的标号用。

bool 数组依旧用来表示是否已经被加入“卷包裹遍历集合”。

代码:

#include
#include
#include
#include
#include
#include
const  double eps=1e-10;
const double PI=acos(-1.0);

using namespace std;


struct Point{
    double x;
    double y;
    Point(double x=0,double y=0):x(x),y(y){}
    void operator<<(Point &A) {cout<eps)-(x<-eps); }
int sgn(double x)  {return (x>eps)-(x<-eps); }
typedef  Point  Vector;

Vector  operator +(Vector A,Vector B) { return Vector(A.x+B.x,A.y+B.y);}

Vector  operator -(Vector A,Vector B) { return Vector(A.x-B.x,A.y-B.y); }

Vector  operator *(Vector A,double p) { return Vector(A.x*p,A.y*p);  }

Vector  operator /(Vector A,double p) {return Vector(A.x/p,A.y/p);}



ostream &operator<<(ostream & out,Point & P) { out<0)    return Length(v3);
    
    else return DistanceToLine(P, A, B);
    
}

Point GetLineProjection(Point P,Point A,Point B)
{
    Vector v=B-A;
    Vector v1=P-A;
    double t=Dot(v,v1)/Dot(v,v);
    
    return  A+v*t;
}

bool  SegmentProperIntersection(Point a1,Point a2,Point b1,Point b2)
{
    double c1=Cross(b1-a1, a2-a1);
    double c2=Cross(b2-a1, a2-a1);
    double c3=Cross(a1-b1, b2-b1);
    double c4=Cross(a2-b1, b2-b1);
    
    return dcmp(c1)*dcmp(c2)<0&&dcmp(c3)*dcmp(c4)<0 ;
    
}

bool  OnSegment(Point P,Point A,Point B)
{
    return dcmp(Cross(P-A, P-B))==0&&dcmp(Dot(P-A,P-B))<=0;
}

double PolygonArea(Point *p,int n)
{
    double area=0;
    
    for(int i=1;i &sol)
{
    double a=L.v.x;
    double b=L.p.x-C.c.x;
    double c=L.v.y;
    double d=L.p.y-C.c.y;
    
    double e=a*a+c*c;
    double f=2*(a*b+c*d);
    double g=b*b+d*d-C.r*C.r;
    
    double delta=f*f-4*e*g;
    
    if(dcmp(delta)<0) return 0;
    
    if(dcmp(delta)==0)
    {
        t1=t2=-f/(2*e);
        sol.push_back(L.point(t1));
        return 1;
    }
    
    else
    {
        t1=(-f-sqrt(delta))/(2*e);
        t2=(-f+sqrt(delta))/(2*e);
        
        sol.push_back(L.point(t1));
        sol.push_back(L.point(t2));
        
        return 2;
    }
    
}

// 向量极角公式

double angle(Vector v)  {return atan2(v.y,v.x);}

int getCircleCircleIntersection(Circle C1,Circle C2,vector &sol)
{
    double d=Length(C1.c-C2.c);
    
    if(dcmp(d)==0)
    {
        if(dcmp(C1.r-C2.r)==0)  return -1;  // 重合
        else return 0;    //  内含  0 个公共点
    }
    
    if(dcmp(C1.r+C2.r-d)<0)  return 0;  // 外离
    if(dcmp(fabs(C1.r-C2.r)-d)>0)  return 0;  // 内含
    
    double a=angle(C2.c-C1.c);
    double da=acos((C1.r*C1.r+d*d-C2.r*C2.r)/(2*C1.r*d));
    
    Point p1=C1.point(a-da);
    Point p2=C1.point(a+da);
    
    sol.push_back(p1);
    
    if(p1==p2)  return 1; // 相切
    else
    {
        sol.push_back(p2);
        return 2;
    }
}


//  求点到圆的切线

int getTangents(Point p,Circle C,Vector *v)
{
    Vector u=C.c-p;
    
    double dist=Length(u);
    
    if(dcmp(dist-C.r)<0)  return 0;
    
    else if(dcmp(dist-C.r)==0)
    {
        v[0]=Rotate(u,PI/2);
        return 1;
    }
    
    else
    {
        
        double ang=asin(C.r/dist);
        v[0]=Rotate(u,-ang);
        v[1]=Rotate(u,+ang);
        return 2;
    }
    
}

//  求两圆公切线


int getTangents(Circle A,Circle B,Point *a,Point *b)
{
    int cnt=0;
    
    if(A.r0)   // 外离   又有两条外公切线
    {
        double  ang_in=acos(rsum/d);
        a[cnt]=A.point(base+ang_in);
        b[cnt]=B.point(base+ang_in+PI);
        cnt++;
        a[cnt]=A.point(base-ang_in);
        b[cnt]=B.point(base-ang_in+PI);
        cnt++;
    }
    
    return cnt;
}


//  几何算法模板

int  isPointInPolygon(Point p,Point * poly,int n)
{
    int wn=0;
    for(int i=0;i0&&d1<=0&&d2>0) wn++;
        if(k<0&&d2<=0&&d1>0) wn--;
        
    }
    
    if(wn!=0)  return 1;
    else   return 0;
    
}

bool vis[100];

int n;





struct event{
    Point p;
    int index;
    
};

event e[100];

bool event_cmp(event a,event b)
{
    return a.p>T;
  
    int temp_int;
    while(T--)
    {
        memset(vis, 0, sizeof(vis));
        
        cin>>n;
        for(int i=0;i


你可能感兴趣的:(ACM_计算几何)