题目:

模板题,注意输入顺序

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const double eps=1e-7;
const int MAXN=1010;
struct Point{
    double x,y;
    Point() {}
    Point(double xx,double yy):x(xx),y(yy) {}
}p[MAXN],a[MAXN];
typedef Point Vector;
struct Line{
    Point P;
    Vector v;
    double ang;
    Line() {}
    Line(Point P,Vector v):P(P),v(v){
        ang=atan2(v.y,v.x);
    }
    bool operator < (const Line & L)const {
        return ang<L.ang;
    }
}L[MAXN],poly[MAXN],q[MAXN];
Point operator + (Vector A,Vector B){return Point(A.x+B.x,A.y+B.y);}
Point operator - (Vector A,Vector B){return Point(A.x-B.x,A.y-B.y);}
Point operator * (Vector A,double p){return Point(A.x*p,A.y*p);}
Point operator / (Vector A,double p){return Point(A.x/p,A.y/p);}
bool operator < (Vector a,Vector b){return a.x<b.x||(fabs(a.x-b.x)<eps&&a.y<b.y);}
double Cross(Vector A,Vector B){return A.x*B.y-A.y*B.x;}
bool Onleft(Line L,Point p){
    return Cross(L.v,p-L.P)>0;
}
Point GetInt(Line a,Line b){
    Vector u=a.P-b.P;
    double t=Cross(b.v,u)/Cross(a.v,b.v);
    return a.P+a.v*t;
}
int n;
bool HalfplaneInt(){
    sort(L,L+n);
    int first=0,last=0;
    q[first]=L[0];
    for(int i=1;i<n;i++){
        while(first<last&&Onleft(L[i],p[last-1])==0) last--;
        while(first<last&&Onleft(L[i],p[first])==0) first++;
        q[++last]=L[i];
        if(fabs(Cross(q[last].v,q[last-1].v))<eps){
            last--;
            if(Onleft(q[last],L[i].P))
                q[last]=L[i];
        }
        if(first<last)
            p[last-1]=GetInt(q[last-1],q[last]);
    }
    while(first<last&&Onleft(q[first],p[last-1])==0) last--;
    if(last-first<=1)
        return 0;
    return 1;
}
int main(){ 
    while(~scanf("%d",&n)){
        if(!n)break;
        for(int i=0;i<n;i++)
            scanf("%lf%lf",&a[i].x,&a[i].y);
        L[0]=Line(a[n-1],a[0]-a[n-1]);
        for(int i=1;i<n;i++)
            L[i]=Line(a[i],a[i]-a[i-1]);
        printf("%d\n",HalfplaneInt());
    }
}