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-6)
#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 equal(S1,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(eq(S1,S2) && eq(S1,S3)){
      puts("NG");
      continue;
    }

    if(!eq(S1,S2) && !eq(S1,S3)){
      puts("NG");
      continue;
    }

    if(check(P[0],P[1],T[0],T[1])){
      ok = true;
    }    
    if(check(P[0],P[2],T[0],T[1])){
      ok = true;
    }  
    if(check(P[1],P[2],T[0],T[1])){
      ok = true;
    }  

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

  return 0;
}

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 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_intersected_ls(point p1, point p2, point p3, point p4) {
  return (ccw(p1,p2,p3)*ccw(p1,p2,p4)<EPS)&&
         (ccw(p3,p4,p1)*ccw(p3,p4,p2)<EPS);
}

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, vector<point> ps, int n){
  segment t;
  t.a=t.b=p;
  t.b.x=DBL_MAX;
  ps.push_back(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;

  int cnt1=0;
  for(int i=0;i<n;i++)
    if(is_point_on_line(t.a,t.b,ps[i]))cnt1++;
  
  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-cnt1)%2;
}

int main(void){
  int n;
  point k,s,in;
  vector<point>p; 

  cin >> n;
  while(n--){
    p.clear();
    for(int i=0;i<3;i++){
      cin >> in.x >> in.y;
      p.push_back(in);
    }     

    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 <iostream>
#include <algorithm>
#include <cmath>
using namespace std;


class Point {
public:
  double x, y;
  Point(double x=0, double y=0) : x(x), y(y) {}
  Point operator - (Point p) { return Point(x - p.x, y - p.y); }
};

typedef Point Vector;

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


Point p1, p2, p3, k, s;

bool isInTry(Point p) {
  double c1 = cross(p2 - p1, p - p1);
  double c2 = cross(p3 - p2, p - p2);
  double c3 = cross(p1 - p3, p - p3);
  return c1 * c2 > 0.0 && c2 * c3 > 0.0;
}

void solve() {
  bool f1 = isInTry(k);
  bool f2 = isInTry(s);
  if((!f1 || !f2) && (f1 || f2)) cout << "OK" << endl;
  else                           cout << "NG" << endl;
}

main() {
  int n;
  cin >> n;
  for(int i = 0; i < n; ++i) {
    cin >> p1.x >> p1.y >> p2.x >> p2.y >> p3.x >> p3.y
	>> k.x >> k.y >> s.x >> s.y;
    solve();
  }
}

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

int x,y,x2,y2,x3,y3,xk,yk,xs,ys;

double len(int xa, int ya,int xb,int yb){
  return sqrt( (xa-xb)*(xa-xb) + (ya-yb)*(ya-yb) );
}

double flon(int xa,int ya, int xb, int yb ,int xc ,int yc){
  double l1,l2,l3,s;
  l1 = len(xa,ya,xb,yb);
  l2 = len(xb,yb,xc,yc);
  l3 = len(xc,yc,xa,ya);
  s = (l1+l2+l3)/2;

  return sqrt( s*(s-l1)*(s-l2)*(s-l3) );
}

bool interk(void){
  if( fabs(flon(x,y,x2,y2,xk,yk) + flon(x,y,x3,y3,xk,yk) + flon(x2,y2,x3,y3,xk,yk) - flon(x,y,x2,y2,x3,y3) ) < 1e-10 )return true;
  else return false;
}

bool inters(void){
  if( fabs(flon(x,y,x2,y2,xs,ys) + flon(x,y,x3,y3,xs,ys) + flon(x2,y2,x3,y3,xs,ys) - flon(x,y,x2,y2,x3,y3) ) < 1e-10 )return true;
  else return false;
}

int main(){
  int n;

  cin >> n;
  while(n){
    n--;
    cin >> x >> y >> x2 >> y2 >> x3 >> y3 >> xk >> yk >> xs >> ys;

    if( !interk() && inters() )cout << "OK" << endl;
    else cout << "NG" << endl;
  }
}