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 <cmath>
#include <cstdio>

using namespace std;

typedef double D; 
#define EPS (1e-10)
#define equal(a,b) (fabs((a)-(b)) < EPS)

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

struct Point{
  D x,y;

  Point (D x = 0, D y = 0) : 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 * (D a) {
    return Point( a*x , a*y );
  }
  
  D norm() {
    return x*x+y*y;
  }

  D dot(Point p){
    return add(x*p.x , y*p.y);
  }

  D det(Point p){
    return add(x*p.y , -y*p.x);
  }  
};

int ccw(Point p0,Point p1,Point p2){
  Point a = p1 - p0;
  Point b = p2 - p0;

  if(a.det(b) > EPS) return 1;
  if(a.det(b) < -EPS) return -1;
  if(a.dot(b) < -EPS) return 2;
  if(a.norm() < b.norm()) return -2;
  return 0;
}

D S(Point p1,Point p2,Point p3){
  D a = sqrt(pow(p1.x-p2.x,2) + pow(p1.y-p2.y,2));
  D b = sqrt(pow(p1.x-p3.x,2) + pow(p1.y-p3.y,2));
  D c = sqrt(pow(p3.x-p2.x,2) + pow(p3.y-p2.y,2));
  D s = (a + b + c) / 2;

  return sqrt(s*(s - a)*(s - b)*(s - c));
}

bool check(Point p1,Point p2,Point p3,Point p4){
  return (ccw(p1,p2,p3)*ccw(p1,p2,p4) < 0 &&
	  ccw(p3,p4,p1)*ccw(p3,p4,p2) < 0);
}

bool eq(D S1,D S2){
  return ((float)S1 == (float)S2);
}

int main(){
  int n;
  Point P[3],T[2];

  cin >> n;
  while(n--){
    scanf("%lf %lf" ,&P[0].x ,&P[0].y);
    scanf("%lf %lf" ,&P[1].x ,&P[1].y);
    scanf("%lf %lf" ,&P[2].x ,&P[2].y);
    scanf("%lf %lf" ,&T[0].x ,&T[0].y);
    scanf("%lf %lf" ,&T[1].x ,&T[1].y);

    bool ok = false;
    D S1 = S(P[0],P[1],P[2]);
    D S2 = S(P[0],P[1],T[0])+S(P[0],P[2],T[0])+S(P[1],P[2],T[0]);
    D S3 = S(P[0],P[1],T[1])+S(P[0],P[2],T[1])+S(P[1],P[2],T[1]);

    if(check(P[0],P[1],T[0],T[1]) &&
       ((eq(S1,S2) && !eq(S1,S3)) || 
	(!eq(S1,S2) && eq(S1,S3)))){
      ok = true;
    }    
    if(check(P[0],P[2],T[0],T[1]) &&
       (eq(S1,S2) && !eq(S1,S3)) ||
       (!eq(S1,S2) && eq(S1,S3))){
      ok = true;
    }  
    if(check(P[1],P[2],T[0],T[1]) &&
       (eq(S1,S2) && !eq(S1,S3)) ||
       (!eq(S1,S2) && eq(S1,S3))){
      ok = true;
    }  

    if(ok){
      puts("OK");
    }else{
      puts("NG");
    }
  }

  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;
                //det=0で解は存在しない(この問題については２線分は同一直線上にないから
                if(fabs(det) > EPS){
                    ansx = (d*p - b*q)/det;
                    if((x[j] - ansx)*(x[j+1] - ansx) <= EPS && (x[3] - ansx)*(x[4] - ansx) <= EPS && fabs(ansx - x[j]) > EPS && fabs(ansx - x[j+1]) > EPS ) {
                        count++;
                    }
                }
            } else {
                a = y[j]-y[0];  b = x[0]-x[j];
                p = x[0]*y[j]-x[j]*y[0];
                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;
                    if((x[j] - ansx)*(x[0] - ansx) <= EPS && (x[3] - ansx)*(x[4] - ansx) <= EPS && fabs(ansx - x[j]) > EPS && fabs(ansx - x[j+1]) > EPS ) {
                        count++;
                    }
                }
            }
        }
        if(count == 1) cout << "OK" << endl;
        else cout << "NG" << endl;
    }
}

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

struct Point
{
	Point(int x, int y):x(x),y(y),z(0){}
	Point():x(0),y(0),z(0){}
	int x,y,z;
};
inline bool isRight( Point &p, Point &a, Point &b ){
	return (a.x-p.x)*(a.y-b.y) - (a.y-p.y)*(a.x-b.x) < 0;
}
bool isInside( Point &p, vector<Point> &vp ){
	for(unsigned int i = 1; i < vp.size(); ++i){
		if( !isRight( p, vp[i-1], vp[i] ) )
			return false;
	}
	return isRight( p, vp[vp.size()-1], vp[0] );
}

int main()
{
	int n;
	cin >> n;
	for(int X = 0; X < n; ++X ){
		Point A, B, C, ken, ori;
		bool  bKenInside = false, bOriInside = false;
		vector<Point> triangle;
		cin >> A.x >> A.y >> B.x >> B.y >> C.x >> C.y >> ken.x >> ken.y >> ori.x >> ori.y;
		triangle.push_back(A);triangle.push_back(B);triangle.push_back(C);

		bKenInside = isInside( ken, triangle );
		bOriInside = isInside( ori, triangle );
		if( ( bKenInside && bOriInside ) ||
			( !bKenInside && !bOriInside ) )
			cout << "NG\n";
		else
			cout << "OK\n";
	}
	return 0;
}