链接 思路:套模板,判断点是否在多边形内部,返回1

#include <bits/stdc++.h>

using namespace std;
int N;
const double eps=1e-8;
int sgn(double x){
    if(fabs(x)<eps) return 0;
    if(x<0) return -1;
    else return 1;
}
struct Point{
    double x,y;
    Point(){}
    Point(double _x,double _y){
        x=_x;
        y=_y;
    }
    void input(){
        scanf("%lf %lf",&x,&y);
    }
    bool operator ==(Point b)const{
        return sgn(x-b.x)==0&&sgn(y-b.y)==0;
    }
    Point operator -(const Point &b)const{
        return Point(x-b.x,y-b.y);
    }
    //点积
    double operator *(const Point &b)const{
        return x*b.x+y*b.y;
    }
    //叉积
    double operator ^(const Point &b)const{
        return x*b.y-y*b.x;
    }
};
struct Line{
    Point s,e;
    Line(){}
    Line(Point _s,Point _e){
        s=_s;
        e=_e;
    }
    bool pointonseg(Point p){
        return sgn((p-s)^(e-s))==0&&sgn((p-s)*(p-e))<=0;
    }
};
struct polygon{
    int n;
    Point p[3];
    Line l[3];
    void input(int _n){
        n=_n;
        for(int i=0;i<n;i++){
            p[i].input();
        }
    }
    void getline(){
        for(int i=0;i<n;i++){
            l[i]=Line(p[i],p[(i+1)%n]);
        }
    }
    int relationpoint(Point q){
        for(int i=0;i<n;i++){
            if(p[i]==q) return 3;
        }
        getline();
        for(int i=0;i<n;i++){
            if(l[i].pointonseg(q)) return 2;
        }
        int cnt=0;
        for(int i=0;i<n;i++){
            int j=(i+1)%n;
            int k=sgn((q-p[j])^(p[i]-p[j]));
            int u=sgn(p[i].y-q.y);
            int v=sgn(p[j].y-q.y);
            if(k>0&&u<0&&v>=0) cnt++;
            if(k<0&&v<0&&u>=0) cnt--;
        }
        return cnt!=0;
    }
};
int main()
{
    scanf("%d",&N);
    while(N--){
        polygon p;
        p.input(3);
        if(p.relationpoint(Point(0,0))==1) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}