Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"strings"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < n; i++ {
		scanner.Scan()
		input := strings.Split(scanner.Text(), " ")
		buf := make([]float64, len(input))
		for j := range buf {
			buf[j], _ = strconv.ParseFloat(input[j], 64)
		}
		p1 := complex(buf[0], buf[1])
		p2 := complex(buf[2], buf[3])
		p3 := complex(buf[4], buf[5])
		pk := complex(buf[6], buf[7])
		ps := complex(buf[8], buf[9])
		kin := isAtSameSide(p3, pk, []complex128{p1, p2}) &&
			isAtSameSide(p1, pk, []complex128{p2, p3}) &&
			isAtSameSide(p2, pk, []complex128{p3, p1})
		sin := isAtSameSide(p3, ps, []complex128{p1, p2}) &&
			isAtSameSide(p1, ps, []complex128{p2, p3}) &&
			isAtSameSide(p2, ps, []complex128{p3, p1})
		if (kin || sin) && !(kin && sin) {
			fmt.Println("OK")
		} else {
			fmt.Println("NG")
		}
	}
}

func isAtSameSide(a, b complex128, line []complex128) bool {
	sa := (real(line[1]) - real(line[0]))*(imag(a)-imag(line[0]))+
		(imag(line[1])-imag(line[0]))*(real(line[0])-real(a))
	sb := (real(line[1]) - real(line[0]))*(imag(b)-imag(line[0]))+
		(imag(line[1])-imag(line[0]))*(real(line[0])-real(b))
	return (sa > 0 && sb > 0) || (sa < 0 && sb < 0)
}

C++: #include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#define rep(i,n) for (int i = 0; (i) < (n); ++ (i))
using namespace std;

int main(void){
    int n;
    cin >> n;
    rep(i,n) {
        int count = 0;
        double x[8],y[8],a,b,c,d,p,q,det;
        //入力を多少簡略化
        for(int i=0;i<8;i++) {
            cin >> x[i] >> y[i];
        }
        rep(j,3) {
            //(x1,y1)(x2,y2)を結ぶax+by=p の係数
            a = y[j]-y[j+1];  b = x[j+1]-x[j];
            p = x[j+1]*y[j]-x[j]*y[j+1];
            //(x3,y3)(x4,y4)を結ぶcx+dy=q の係数
            c = y[6]-y[7];  d = x[7]-x[6];
            q = x[7]*y[6]-x[6]*y[7];
            //係数についての行列式
            det = a*d-c*b;
            //det=0で解は存在しない(この問題については２線分は同一直線上にないから)
            if(fabs(det) < 0.00001){
            } else {
                ansx = (d*p - b*q)/det;
                ansy = (-c*p + a*q)/det;
                //ansxがどちらの線分のx座標範囲にも含まれるかを判定
                if((x[0] - ansx)*(x[1] - ansx) <= 0.00001 && (x[6] - ansx)*(x[7] - ansx) <= 0.00001 ) {
                    count++;
                }
            }
        }
        if(count == 1) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}

C++: #include "bits/stdc++.h"
using namespace std;

typedef long long lli;
typedef pair<int,int> pii;
#define rep(i,n) for(lli i=0;i<(lli)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 999999999

#define F first
#define S second

#define EPS 1e-9

double f(pii a,pii b,pii c){
    pii p1,p2;
    p1=pii( a.F-b.F , a.S-b.S );
    p2=pii( a.F-c.F , a.S-c.S );
    
    return p1.F*p2.S-p1.S*p2.F;
}


int main(){
    int n;
    cin>>n;
    rep(hoge,n){
        pii p1,p2,p3,k,s;
        cin>>p1.F>>p1.S>>p2.F>>p2.S>>p3.F>>p3.S>>k.F>>k.S>>s.F>>s.S;
        
        
        double a=f(p1,p2,k);
        double b=f(p2,p3,k);
        double c=f(p3,p1,k);
        
        bool x;
        
        if( (a>=0&&b>=0&&c>=0) || (a<0+EPS&&b<0+EPS&&c<0+EPS) )x=true;
        else x=false;

    
        a=f(p1,p2,s);
        b=f(p2,p3,s);
        c=f(p3,p1,s);
        
        bool y;
        
        if( (a>=0&&b>=0&&c>=0) || (a<0+EPS&&b<0+EPS&&c<0+EPS) )y=true;
        else y=false;
        if(x==y)cout<<"NG"<<endl;
        else cout<<"OK"<<endl;
    }

}

C++: #include <iostream>
#include <stdio.h>

using namespace std;

int hantei(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy) {
	double y,m,n,d;
	if ((bx-ax==0 && dx-cx==0) || (by-ay==0 && dy-cy==0)) return 0; 
	if (dx-cx!=0) m=(dy-cy)/(dx-cx);
	if (bx-ax!=0) n=(by-ay)/(bx-ax);
	if (ax==bx) {
        if (cy==dy && ((cy>ay && cy<by) || (cy>by && cy<ay)) && ((cx<ax && dx>ax) || (dx<ax && cx>ax))) return 1;
        y=cy+m*(ax-cx);
		if (((y>cy && y<dy) || (y>dy && y<cy)) && ((y>ay && y<by) || (y>by && y<ay))) return 1;
		return 0;} 
	if (cx==dx) {
		y=ay+n*(cx-ax);
		if (((y>cy && y<dy) || (y>dy && y<cy)) && ((y>ay && y<by) || (y>by && y<ay))) return 1;
		return 0;}
	d=(ay-cy+m*cx-n*ax)/(m-n);
	if (((d>cx && d<dx) || (d>dx && d<cx)) &&((d>ax && d<bx) || (d>bx && d<ax)))  return 1;
	return 0;
}

int main() {
	int n,f;
	double xp1,yp1,xp2,yp2,xp3,yp3,xk,yk,xs,ys;
	cin >> n;
	for (;n>0;n--) {
		cin >> xp1 >> yp1 >> xp2 >> yp2 >> xp3 >> yp3 >> xk >> yk >> xs >> ys;
        f=hantei(xp1,yp1,xp2,yp2,xk,yk,xs,ys)+hantei(xp2,yp2,xp3,yp3,xk,yk,xs,ys)+hantei(xp1,yp1,xp3,yp3,xk,yk,xs,ys);
		if (f==1) cout << "OK"; else cout << "NG";
		cout << endl;
	}
return 0;
	}