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>

using namespace std;

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

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))
#define EPS 1e-10
using namespace std;

int main(void){
    int n;
    cin >> n;
    rep(i,n) {
        int count = 0;
        double x[5],y[5],a,b,c,d,p,q,det,ansx;
        for(int k=0;k<5;k++) {
            cin >> x[k] >> y[k];
        }
        rep(j,3) {
            if(j != 2) {
                a = y[j]-y[j+1];  b = x[j+1]-x[j];
                p = x[j+1]*y[j]-x[j]*y[j+1];
                c = y[3]-y[4];  d = x[4]-x[3];
                q = x[4]*y[3]-x[3]*y[4];
                //係数についての行列式
                det = a*d-c*b;
                if(fabs(det) > EPS){
                    ansx = (d*p - b*q)/det;
                    //ansxがどちらの線分のx座標範囲にも含まれるかを判定
                    if((x[j] - ansx)*(x[j+1] - ansx) <= EPS && (x[3] - ansx)*(x[4] - ansx) <= EPS ) {
                        count++;
                    }
                }
            } else {
                a = y[j]-y[0];  b = x[0]-x[j];
                p = x[0]*y[j]-x[j]*y[0];
                //(x3,y3)(x4,y4)を結ぶcx+dy=q の係数
                c = y[3]-y[4];  d = x[4]-x[3];
                q = x[4]*y[3]-x[3]*y[4];
                //係数についての行列式
                det = a*d-c*b;
                //det=0で解は存在しない(この問題については２線分は同一直線上にないから
                if(fabs(det) > EPS){
                    ansx = (d*p - b*q)/det;
                    //ansxがどちらの線分のx座標範囲にも含まれるかを判定
                    if((x[j] - ansx)*(x[0] - ansx) <= EPS && (x[3] - ansx)*(x[4] - ansx) <= EPS ) {
                        count++;
                    }
                }
            }
        }
        if(count == 1) cout << "OK" << endl;
        else cout << "NG" << endl;
    }
}

C++: #include <iostream>
#include <vector>
#include <complex>
using namespace std;
const double INF = 1e12;
typedef complex<double> P,point;
typedef vector<P> G,polygon;
namespace std {bool operator < (const P& a, const P& b) {return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);}}
double cross(const P& a, const P& b) {return imag(conj(a)*b);}
double dot(const P& a, const P& b) {return real(conj(a)*b);}
struct L : public vector<P> {L(const P &a, const P &b) {push_back(a); push_back(b);}};
int ccw(P a, P b, P c) {b -= a; c -= a;if (cross(b, c) > 0)   return +1;if (cross(b, c) < 0)   return -1;if (dot(b, c) < 0) return +2;if (norm(b) < norm(c)) return -2;return 0;}
bool intersectSS(const L &s, const L &t) {return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 && ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;}

// Where is Point in Polygon? //
#define curr(P, i) P[i]
#define next(P, i) P[(i+1)%P.size()]
enum { OUT, ON, IN };
int contains(const polygon& P, const point& p) {bool in = false;for (int i = 0; i < P.size(); ++i) {point a = curr(P,i) - p, b = next(P,i) - p;if (imag(a) > imag(b)) swap(a, b);if (imag(a) <= 0 && 0 < imag(b))if (cross(a, b) < 0) in = !in;if (cross(a, b) == 0 && dot(a, b) <= 0) return ON;}return in ? IN : OUT;}

#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int n;cin >> n;
	while(n--){
		P data[5];
		G v;
		rep(i,3){P c; cin >> c.real() >> c.imag(); v.push_back(c);}
		P a,b;
		cin >> a.real() >> a.imag() >> b.real() >> b.imag();
		cout << ( (!!contains(v,a)) ^ (!!contains(v,b)) ?"OK":"NG") << endl;
	}
}