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

#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b)) < EPS)
#define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))
typedef complex<double> Po;

Po unit(Po p){return p / abs(p);}
  
Po normal(Po p,int m){
  Po x;
  if(!m)x = p * Po(0,1);
  else x = p * Po(0,-1);
  return x;
}

double dot(Po x,Po y){return x.real()*y.real() + x.imag()*y.imag();}

double cross(Po x,Po y){return x.real()*y.imag() - x.imag()*y.real();}

double area(Po a,Po b,Po c){
  return abs(cross(b-a,c-a)/2);
}

double heron(Po a,Po b,Po c){
  double l1,l2,l3,s;
  l1 = abs(a-b);
  l2 = abs(b-c);
  l3 = abs(c-a);
  s = (l1+l2+l3)/2;
  return sqrt(s*(s-l1)*(s-l2)*(s-l3));
}

bool inter(Po a,Po b,Po c,Po x){
  if( heron(a,b,x) + heron(b,c,x) + heron(c,a,x) > heron(a,b,c) + EPS)return false;
  else return true;
}

class line{
 public:
  Po a,b;

  void set(Po x,Po y){
    a = x;
    b = y;
  }

  bool orth(line l){
    return EQ( dot(a-b,l.a-l.b),0.0);
  }

  bool para(line l){
    return EQ( cross(a-b,l.a-l.b),0.0);
  }

  bool on_line(Po x){
    return EQ( cross(b-a,x-a),0.0);
  }

  double line_dis(Po x){
    return abs(cross(b-a,x-a))/abs(b-a);
  }

  Po line_cp(line l){
    return a + (b-a)*cross(l.b-l.a,l.a-a) /cross(l.b-l.a,b-a);
  }

  bool on_seg(Po x){
    return (abs(a-x) + abs(x-b) < abs(a-b) + EPS);
  }

  double seg_dis(Po x){
    if(dot(b-a,x-a)<EPS)return abs(x-a);
    if(dot(a-b,x-b)<EPS)return abs(x-b);
    return abs(cross(b-a,x-a))/abs(b-a);
  }

  int is_cross(line l){
    return (cross(b-a,l.a-a) * cross(b-a,l.b-a)<EPS) && (cross(l.b-l.a,a-l.a) * cross(l.b-l.a,b-l.a) < EPS);
  }

  Po seg_cp(line l){
    double d = abs(cross(l.b-l.a,a-l.a));
    return a + (b-a)*( d / (d * abs(cross(l.b-l.a,b-l.a))));
  }
};

class polygon{
 public:
  vector<Po> v;
  int o;

  void set(void){
    v.clear();
  }

  void Vadd(Po a){
    if(!v.size())o = 0;
    else if(a.imag() < v[o].imag())o = v.size();
    v.push_back(a);
  }

  void sort(void){
    vector<double> seta;
    Po ot;
    ot.real() = 1.0;
    ot.imag() = 0.0;
    swap(v[0],v[o]);
    o = 0;
    for(int i=1;i<(int)v.size();i++){
      seta.push_back(dot(ot,v[i]-v[0]) / (abs(ot)*abs(v[i]-v[0])) );
    } 
    for(int i=1;i<(int)v.size()-1;i++){
      for(int j=i+1;j<(int)v.size();j++){
	if(seta[i-1] < seta[j-1]){
	  swap(seta[i-1],seta[j-1]);
	  swap(v[i],v[j]);
	}
      }
    }
  }

  bool inter(Po a){
    int c = 0;
    double max = 0;
    Po b;
    line l,s;
    for(int i=0;i<(int)v.size();i++)if(max < v[i].real())max = v[i].real();
    b.real() = max+1;
    b.imag() = a.imag();
    s.set(a,b);
    for(int i=0;i<(int)v.size()-1;i++){
      l.set(v[i],v[i+1]);
      if(s.is_cross(l))c++;
    }
    l.set(v[(int)v.size()-1],v[0]);
    if(s.is_cross(l))c++;
    if(c%2)return true;
    else return false;
  }
};

int main(){
  int n;
  Po p1,p2,p3,pk,ps;
  polygon tri;

  cin >> n;

  for(int i=0;i<n;i++){
    cin >> p1.real() >> p1.imag();
    cin >> p2.real() >> p2.imag();
    cin >> p3.real() >> p3.imag();
    cin >> pk.real() >> pk.imag();
    cin >> ps.real() >> ps.imag();
    /*
    tri.set();
    tri.Vadd(p1);
    tri.Vadd(p2);
    tri.Vadd(p3);
    tri.sort();
    */
    //if(tri.inter(pk) != tri.inter(ps))cout << "OK" << endl;
    if(inter(p1,p2,p3,pk) != inter(p1,p2,p3,ps) )cout << "OK" << endl;
    else cout << "NG" << endl;
  }
  
}

C++: #include <cstdio>
#include <cmath>
#define EPS 1e-10
struct vektor{
	double x,y;
	vektor(){}
	vektor(double xx,double yy){
		x=xx;
		y=yy;
	}
	vektor operator +(vektor v){
		return vektor(x+v.x,y+v.y);
	}

	vektor operator -(vektor v){
		return vektor(x-v.x,y-v.y);
	}
	vektor operator *(double d){
		return vektor(x*d,y*d);
	}
};

int n;
vektor vek[5];

bool check(){
	vektor v[5];
	for(int i=1;i<=4;i++){
		v[i]=vek[i]-vek[0];
	}
	double s=(v[3].x*v[2].y-v[3].y*v[2].x)/(v[1].x*v[2].y-v[1].y*v[2].x);
	double t=(v[3].x*v[1].y-v[3].y*v[1].x)/(v[1].y*v[2].x-v[1].x*v[2].y);
	int data3,data4;
	if(s>0 && t>0 && s+t<1)data3=1;
	else data3=-1;
	s=(v[4].x*v[2].y-v[4].y*v[2].x)/(v[1].x*v[2].y-v[1].y*v[2].x);
	t=(v[4].x*v[1].y-v[4].y*v[1].x)/(v[1].y*v[2].x-v[1].x*v[2].y);
	if(s>0 && t>0 && s+t<1)data4=1;
	else data4=-1;
	return data3*data4<0;
}

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		for(int j=0;j<5;j++){
			scanf("%lf %lf",&vek[j].x,&vek[j].y);
		}
		bool flag=check();
		printf("%s\n",flag?"OK":"NG");
	}
	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(){for(cin>>A.x;cin>>A.x>>A.y>>B.x>>B.y>>C.x>>C.y>>S.x>>S.y>>G.x>>G.y;X(S)^X(G)?cout<<"OK\n":cout<<"NG\n"){A-=C;B-=C;S-=C;G-=C;}}

C++: #include <stdio.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <fstream>
#include <sstream>
#include <math.h>
#include <queue>
#include <stack>
#include <math.h>
#include <string.h>
#include <set>


using namespace std;

//二次元の外積
//回転の方向
double gaiseki(double x1, double y1, double x2, double y2){
    return x1*y2-x2*y1;
}

bool inside_outside_of_triangle(double xpa, double ypa, double xpb, double ypb, double xpc, double ypc, double x, double y){
    double vab_x = xpa-xpb;
    double vab_y = ypa-ypb;
    double vbc_x = xpb-xpc;
    double vbc_y = ypb-ypc;
    double vca_x = xpc-xpa;
    double vca_y = ypc-ypa;
    double vap_x = xpa-x;
    double vap_y = ypa-y;
    double vbp_x = xpb-x;
    double vbp_y = ypb-y;
    double vcp_x = xpc-x;
    double vcp_y = ypc-y;
    
    double direction_a = gaiseki(vca_x,vca_y,vap_x,vap_y);
    double direction_b = gaiseki(vab_x,vab_y,vbp_x,vbp_y);
    double direction_c = gaiseki(vbc_x,vbc_y,vcp_x,vcp_y);
    
    direction_a/=fabs(direction_a);
    direction_b/=fabs(direction_b);
    direction_c/=fabs(direction_c);
    
    if(direction_a==direction_b&&direction_b==direction_c)return true;
    else return false;

}



int main(){
    int n;
    while(cin>>n){
        for(int i=0; i<n; i++){
            double xp1, yp1, xp2, yp2, xp3, yp3, xk, yk, xs, ys;
            cin>>xp1>>yp1>>xp2>>yp2>>xp3>>yp3>>xk>>yk>>xs>>ys;
            bool in_bega = inside_outside_of_triangle(xp1, yp1, xp2, yp2, xp3, yp3, xs, ys);
            bool in_altair = inside_outside_of_triangle(xp1, yp1, xp2, yp2, xp3, yp3, xk, yk);
            if((in_bega&&!in_altair)||(!in_bega&&in_altair))cout<<"OK"<<endl;
            else cout<<"NG"<<endl;
        }
   
    }
}