Problem:
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

A Point in a Triangle

There is a triangle formed by three points $(x_1, y_1)$, $(x_2, y_2)$, $(x_3, y_3)$ on a plain.

Write a program which prints "YES" if a point $P$ $(x_p, y_p)$ is in the triangle and "NO" if not.

Input

Input consists of several datasets. Each dataset consists of:

$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_p$ $y_p$

All the input are real numbers. Input ends with EOF. The number of datasets is less than or equal to 100.

Constraints

You can assume that:

$ -100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_p, y_p \leq 100$

1.0 $\leq$ Length of each side of a tringle

0.001 $\leq$ Distance between $P$ and each side of a triangle

Output

For each dataset, print "YES" or "NO" in a line.

Sample Input

0.0 0.0 2.0 0.0 2.0 2.0 1.5 0.5
0.0 0.0 1.0 4.0 5.0 3.0 -1.0 3.0

Output for the Sample Input

YES
NO

Solution in C# (judge verdict: Accepted)

using System;
using System.Collections.Generic;
class _0012
{
    public static void Main()
    {
        char[] splitChar = { ' ' };
        string str;
        List<string> judges = new List<string>();
        double aBAC, aBAP, aCBA, aCBP, aACB, aACP;
        while ((str = Console.ReadLine()) != null)
        {
            string[] data = str.Split(splitChar);
            vector2 a = new vector2(double.Parse(data[0]), double.Parse(data[1]));
            vector2 b = new vector2(double.Parse(data[2]), double.Parse(data[3]));
            vector2 c = new vector2(double.Parse(data[4]), double.Parse(data[5]));
            vector2 p = new vector2(double.Parse(data[6]), double.Parse(data[7]));
            vector2 ab = new vector2((b - a).getX, (b - a).getY);
            vector2 ac = new vector2((c - a).getX, (c - a).getY);
            vector2 bc = new vector2((c - b).getX, (c - b).getY);
            vector2 pa = new vector2((a - p).getX, (a - p).getY);
            vector2 pb = new vector2((b - p).getX, (b - p).getY);
            vector2 pc = new vector2((c - p).getX, (c - p).getY);
            aBAC = Math.Acos((Math.Pow(ab.size, 2.0) + Math.Pow(ac.size, 2.0) - Math.Pow(bc.size, 2.0)) / (2.0 * ab.size * ac.size));
            aCBA = Math.Acos((Math.Pow(ab.size, 2.0) + Math.Pow(bc.size, 2.0) - Math.Pow(ac.size, 2.0)) / (2.0 * ab.size * bc.size));
            aACB = Math.Acos((Math.Pow(ac.size, 2.0) + Math.Pow(bc.size, 2.0) - Math.Pow(ab.size, 2.0)) / (2.0 * ac.size * bc.size));
            aBAP = Math.Acos((Math.Pow(ab.size, 2.0) + Math.Pow(pa.size, 2.0) - Math.Pow(pb.size, 2.0)) / (2.0 * ab.size * pa.size));
            aCBP = Math.Acos((Math.Pow(bc.size, 2.0) + Math.Pow(pb.size, 2.0) - Math.Pow(pc.size, 2.0)) / (2.0 * bc.size * pb.size));
            aACP = Math.Acos((Math.Pow(ac.size, 2.0) + Math.Pow(pc.size, 2.0) - Math.Pow(pa.size, 2.0)) / (2.0 * ac.size * pc.size));
            if (aBAC > aBAP && aCBA > aCBP && aACB > aACP)
            {
                judges.Add("YES");
            }
            else
            {
                judges.Add("NO");
            }
        }
        for (int i = 0; i < judges.Count; i++) Console.WriteLine(judges[i]);
    }
    private double dotProduct(vector2 x, vector2 y)
    {
        return x.getX * y.getX + x.getY * y.getY;
    }
}
class vector2
{
    private double x, y;
    public vector2() { x = 0.0; y = 0.0; }
    public vector2(double i, double j) { x = i; y = j; }
    public static vector2 operator +(vector2 op1, vector2 op2)
    {
        vector2 result = new vector2();
        result.x = op1.x + op2.x;
        result.y = op1.y + op2.y;
        return result;
    }
    public static vector2 operator -(vector2 op1, vector2 op2)
    {
        vector2 result = new vector2();
        result.x = op1.x - op2.x;
        result.y = op1.y - op2.y;
        return result;
    }
    public static vector2 operator /(vector2 op1, double op2)
    {
        vector2 result = new vector2();
        result.x = op1.x / op2;
        result.y = op1.y / op2;
        return result;
    }
    public static double operator &(vector2 op1, vector2 op2)
    {
        return op1.x * op2.x + op1.y * op2.y;
    }
    public double size
    {
        get
        {
            return Math.Sqrt(Math.Pow(x, 2.0) + Math.Pow(y, 2.0));
        }
    }
    public double getX{
        get{
            return x;
        }
    }
    public double getY{
        get{
            return y;
        }
    }
}