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>
using namespace std;

struct Point
{
  int x;
  int y;
};

//-----------------------Line Class
class Line
{
public:
  Line(Point a, Point b);
  double GetSlope();
  double GetIntercept();
  Point GetPointA();
  Point GetPointB();
  bool CrossLine(Line line2);
private:
  Point m_pointA,m_pointB;
  bool m_x1_x2;         //x1=x2 ?
  double m_slope;       //傾き
  double m_intercept;   //y切片
};

Line::Line(Point a, Point b)
{
  m_pointA = a;
  m_pointB = b;

  if ( m_pointA.x == m_pointB.x )
  {
    m_x1_x2 = true;
  }
  else
  {
    m_x1_x2 = false;
    m_slope = ( m_pointB.y - m_pointA.y) / (double)( m_pointB.x - m_pointA.x );
    m_intercept = m_pointA.y - m_pointA.x * m_slope;
  }
}

double Line::GetSlope()
{
  return m_slope;
}

double Line::GetIntercept()
{
  return m_intercept;
}

Point Line::GetPointA()
{
  return m_pointA;
}

Point Line::GetPointB()
{
  return m_pointB;
}

bool Line::CrossLine(Line line2)
{
  if ( m_slope == line2.GetSlope() )    //傾きが同じならば
  {
    return false;
  }
  double cross_x = ( m_intercept - line2.GetIntercept() ) / ( m_slope - line2.GetSlope() );
  bool line1_in;
  bool line2_in;
  if ( m_pointA.x == m_pointB.x )   //self
  {
    line1_in = true;
  }
  else if ( (m_pointA.x < cross_x && cross_x < m_pointB.x) || 
            (m_pointB.x < cross_x && cross_x < m_pointA.x) )
  {
    line1_in = true;
  }
  else
  {
    line1_in = false;
  }

  if ( line2.GetPointA().x == line2.GetPointB().x )   //引数line2
  {
    line2_in = true;
  }
  else if ( (line2.GetPointA().x < cross_x && cross_x < line2.GetPointB().x) || 
            (line2.GetPointB().x < cross_x && cross_x < line2.GetPointA().x) )
  {
    line2_in = true;
  }
  else
  {
    line2_in = false;
  }

  return line1_in && line2_in;
}

//--------------------------Triangle Class
class Triangle
{
public:
  Triangle(Point point1, Point point2, Point point3);
  bool OnePointIn( Point point1, Point point2);
private:
  Point m_point1, m_point2, m_point3;
};

Triangle::Triangle(Point point1, Point point2, Point point3)
{
  m_point1 = point1;
  m_point2 = point2;
  m_point3 = point3;
}

bool Triangle::OnePointIn( Point point1, Point point2 )
{
  Line love(point1, point2);
  Line trg1(m_point1, m_point2);
  Line trg2(m_point1, m_point3);
  Line trg3(m_point2, m_point3);
  int cross_num = 0;
  if ( love.CrossLine(trg1) )
  {
    cross_num++;
  }
  if ( love.CrossLine(trg2) )
  {
    cross_num++;
  }
  if ( love.CrossLine(trg3) )
  {
    cross_num++;
  }
  if ( cross_num == 1 )
  {
    return true;
  }
  else
  {
    return false;
  }
}

//----------------------------main関数
int main()
{
  int n;    //  データセットの個数
  cin >> n;
  for (int dataset=0; dataset<n; dataset++)
  {
    Point trg[3];
    for (int i=0; i<3; i++)
    {
      cin >> trg[i].x >> trg[i].y;
    }
    Triangle triangle( trg[0], trg[1], trg[2] );
    Point kengyu;
    Point shukujo;
    cin >> kengyu.x >> kengyu.y >> shukujo.x >> shukujo.y;
    if ( triangle.OnePointIn( kengyu, shukujo ) )
    {
      cout << "OK" << endl;
    }
    else
    {
      cout << "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 );
}

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;
}