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 <bits/stdc++.h>
using namespace std;
typedef double frac;
typedef complex<frac> Pt;
struct less_c{
    bool operator() (const Pt& a, const Pt& b){
	    return a.real()!=b.real() ? a.real()<b.real() : a.imag()<b.imag();
    }
};
frac cross(Pt a, Pt b){ //外積
    return a.real()*b.imag()-a.imag()*b.real();
}

bool in_convex(vector<Pt> p, Pt q){
    vector<Pt> pp=p;
    pp.push_back(q);
    
    int n=pp.size();
    sort(pp.begin(),pp.end(),less_c());
    vector<Pt> ch(2);
    for(int i=0; i<2; i++) ch[i]=pp[i];
    for(int i=2; i<n; i++){
        for(int j=ch.size()-1; j>0; j--){
            if(cross(pp[i]-ch[j],ch[j-1]-ch[j])<0){
                ch.erase(ch.begin()+j);
            }else{
                break;
            }
        }
        ch.push_back(pp[i]);
    }
    
    int half=ch.size()-1;
    ch.push_back(pp[n-2]);
    for(int i=n-3; i>=0; i--){
        for(int j=ch.size()-1; j>half; j--){
            if(cross(pp[i]-ch[j],ch[j-1]-ch[j])<0){
                ch.erase(ch.begin()+j);
            }else{
                break;
            }
        }
        ch.push_back(pp[i]);
    }
    ch.pop_back();

    sort(ch.begin(),ch.end(),less_c());
    sort(p.begin(),p.end(),less_c());
    return ch==p;
}

int main(){
	int n;  cin >> n;
    for(int i=0; i<n; i++){
        int x, y;
        vector<Pt> p(3);
        for(int j=0; j<3; j++){
            cin >> x >> y;
            p[j]={frac(x),frac(y)};
        }
        Pt k, s;
        cin >> x >> y;  k={frac(x),frac(y)};
        cin >> x >> y;  s={frac(x),frac(y)};
        
        cout << (in_convex(p,k)!=in_convex(p,s) ? "OK" : "NG") << endl; 
    }
}

C++: #include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<climits>
#include<cfloat>
 
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);
  }
};
 
struct segment{
  point a,b;
};
 
double dot(point a, point b) {
  return (a.x * b.x + a.y * b.y);
}
 
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 );
}

 double vec_abs(point a){
  return sqrt(a.x*a.x+a.y*a.y);
}

int ccw(point p0, point p1, point p2){
  point a = p1 - p0;
  point b = p2 - p0;
  if(cross(a,b)>EPS)return +1;
  if(cross(a,b)<EPS)return -1;
  if(dot(a,b)<-EPS)return +2;
  if(a.x*a.x+a.y*a.y<b.x*b.x+b.y*b.y)return -2;
  return 0;
}

int is_point_on_line(point a, point b, point c) {
  return cross(b-a, c-a)==0.0 &&
         (dot(b-a, c-a) > -EPS) &&
         (dot(a-b, c-b) > -EPS);
}

int inside(point p, point* ps, int n){
  segment t;
  t.a=t.b=p;
  t.b.x=DBL_MAX;
  ps[n]=ps[0];
  double ymx=-DBL_MAX,ymn=DBL_MAX;
  for(int i=0;i<n;i++){
    ymx=max(ymx,ps[i].y);
    ymn=min(ymn,ps[i].y);
  }
  if(t.a.y<=ymn||t.a.y>=ymx)return 0;

  double xmx=-DBL_MAX,xmn=DBL_MAX;
  for(int i=0;i<n;i++){
    xmx=max(xmx,ps[i].x);
    xmn=min(xmn,ps[i].x);
  }
  if(t.a.x<=xmn||t.a.x>=xmx)return 0;

  int cnt=0;
  for(int i=0;i<n;i++){
    if(is_intersected_ls(ps[i],ps[i+1],t.a,t.b))cnt++;
  }

  return cnt%2;
}

int main(void){
  int n;
  point p[4],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;

    if(inside(k,p,3)!=inside(s,p,3))cout << "OK" << endl;
    else cout << "NG" << endl;
     
  }
 
  return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef complex<double> P;
static const double EPS = 1e-3;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
double cross(P a, P b) {
  return (a.real() * b.imag() - a.imag() * b.real());
}
int main(void){
  int n;
  cin>>n;
  while(n--){
    vector<P> point(5);
    REP(i,5){
      double x,y;
      cin>>x>>y;
      point[i] = P(x,y);
    }
    double S = abs(cross(point[2]-point[0],point[1]-point[0]));
    double par = 0;
    bool in1,in2;
    REP(i,3){
      par += abs(cross(point[i]-point[3],point[(i+1)%3]-point[3]));
    }
    in1 = (abs(S-par)<EPS);
    par = 0;
    REP(i,3){
      par += abs(cross(point[i]-point[4],point[(i+1)%3]-point[4]));
    }
    in2 = (abs(S-par)<EPS);
    if((in1&&in2)||!(in1||in2)){
      cout<<"NG"<<endl;
    }else{
      cout<<"OK"<<endl;
    }
  }



  return 0;
}