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 k=0;k<8;k++) {
            cin >> x[k] >> y[k];
        }
        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 << "OK" << endl;
        else cout << "NG" << endl;
    }
}

C++: #include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>

using namespace std;

double EPS = 1e-10;

double add(double a, double b){
  if(abs(a+b) < EPS * (abs(a)+abs(b)))return 0;
  return a+b;
}

struct point{
  double x, y;
  point(){}
  point(double x,double y) : x(x) , y(y){}

  point operator + (point p){
    return point(add(x,p.x), add(y,p.y));
  }

  point operator - (point p){
    return point(add(x,-p.x), add(y,-p.y));
  }

  point operator * (double d){
    return point(x*d,y*d);
  }
};

double cross(point a, point b) {
  return (a.x * b.y - a.y * b.x);
}

int is_intersected_ls(point a1, point a2, point b1, point b2) {
  return ( cross(a2-a1, b1-a1) * cross(a2-a1, b2-a1) < EPS ) &&
         ( cross(b2-b1, a1-b1) * cross(b2-b1, a2-b1) < EPS );
}

int main(void){
  int n;
  point p[3],k,s;

  cin >> n;
  while(n--){
    for(int i=0;i<3;i++)
      cin >> p[i].x >> p[i].y;
    
    cin >> k.x >> k.y >> s.x >> s.y;
    int cnt=0;
    for(int i=0;i<3;i++)
      for(int j=i+1;j<3;j++)
	if(i!=j)
	  cnt+=is_intersected_ls(p[i],p[j],k,s);
    
    if(cnt%2)cout << "OK" << endl;
    else cout << "NG" << endl;
    
  }

  return 0;
}

C++: #include<iostream>
using namespace std;struct P{float x,y;int operator-=(P&a){x-=a.x;y-=a.y;}};P A,B,C,S,G;int X(P S){C.x=(B.y*S.x-B.x*S.y)/(A.x*B.y-A.y*B.x);C.y=(A.y*S.x-A.x*S.y)/(A.y*B.x-A.x*B.y);return C.x>0&&C.y>0&&C.x+C.y<1;}main(){cin>>A.x;while(cin>>A.x>>A.y>>B.x>>B.y>>C.x>>C.y>>S.x>>S.y>>G.x>>G.y){A-=C;B-=C;S-=C;G-=C;X(S)^X(G)?cout<<"OK":cout<<"NG";cout<<endl;}return 0;}

C++: #include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;
struct Point { long double px, py; };
Point Minus(Point a, Point b) { Point O; O.px = a.px - b.px; O.py = a.py - b.py; return O; }
long double dot(const Point& a, const Point& b) { return a.px * b.px + a.py * b.py; }
long double crs(const Point& a, const Point& b) { return a.px * b.py - a.py * b.px; }
int contain(vector<Point> v, Point p) {
	bool in = false;
	for (int i = 0; i < v.size(); ++i) {
		Point a = Minus(v[i], p), b = Minus(v[(i + 1) % v.size()], p);
		if (a.py > b.py) swap(a, b);
		if (a.py <= 0 && 0 < b.py)
			if (crs(a, b) < 0) in = !in;
		if (crs(a, b) == 0 && dot(a, b) <= 0) return 1;
	}
	return in ? 2 : 0;
}
int main() {
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		Point p1, p2, p3, p4, p5;
		cin >> p1.px >> p1.py >> p2.px >> p2.py >> p3.px >> p3.py >> p4.px >> p4.py >> p5.px >> p5.py;
		vector<Point>C = { p1,p2,p3 };
		bool G1 = contain(C, p4), G2 = contain(C, p5);
		if (G1 ^ G2 == true)cout << "OK" << endl;
		else { cout << "NG" << endl; }
	}
	return 0;
}

C++: #include <iostream>
using namespace std;

struct point{
	double x;
	double y;
};

int ccw(point p0, point p1, point p2){
	double dx1 = p1.x - p0.x, dy1 = p1.y - p0.y;
	double dx2 = p2.x - p0.x, dy2 = p2.y - p0.y;
	if(dx1 * dy2 > dx2 * dy1){
		return 1;
	}else if(dx1 * dy2 > dx2 * dy1){
		return -1;
	}
	return 0;
}

bool in_t(point p0, point p1, point p2, point p3){
	if((ccw(p0, p1, p2) == -ccw(p0, p1, p3)
		&& (ccw(p0, p2, p1) == -ccw(p0, p2, p3))))
		return true;
	else return false;
}


int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		point p1, p2, p3;
		point pk, ps;
		cin >> p1.x >> p1.y >> p2.x >> p2.y
			>> p3.x >> p3.y >> pk.x >> pk.y >>  ps.x >> ps.y;
		if((in_t(pk, p1, p2, p3) && !in_t(ps, p1, p2, p3)) ||
			(!in_t(pk, p1, p2, p3) && in_t(ps, p1, p2, p3)))
			cout << "OK" << endl;
		else cout << "NG" << endl;
	}
	return 0;
}