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



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


Sample output:
YES
NO

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import cmath
import math

class Point(object):
    def __init__(self, x, y):
        self.point = complex(x, y)

    def __str__(self):
        return "x = {0}, y = {1}".format(self.point.real, self.point.imag)


class Triangle(Point):
    def __init__(self, a, b, c):
        self.a = a
        self.b = b
        self.c = c

        # ３辺の長さ
        self.edgeA = abs(b.point-c.point)
        self.edgeB = abs(c.point-a.point)
        self.edgeC = abs(a.point-b.point)

        # ３角の大きさ
        self.angleA = Triangle.angle(self.edgeA, self.edgeB, self.edgeC)
        self.angleB = Triangle.angle(self.edgeB, self.edgeC, self.edgeA)
        self.angleC = Triangle.angle(self.edgeC, self.edgeA, self.edgeB)

    # 角度を求める
    def angle(A, B, C):
        return cmath.acos( (B*B+C*C-A*A)/(2*B*C) ).real


eps = 0.0001
for line in sys.stdin:
    line = [float(x) for x in line.split()]
    p1 = Point(line[0], line[1])
    p2 = Point(line[2], line[3])
    p3 = Point(line[4], line[5])
    P  = Point(line[6], line[7])
    t1 = Triangle(p1, p2, P)
    t2 = Triangle(p2, p3, P)
    t3 = Triangle(p3, p1, P)
    if (math.degrees(t1.angleC + t2.angleC + t3.angleC) <= 360+eps) and (math.degrees(t1.angleC + t2.angleC + t3.angleC) >= 360-eps):
        print("YES")
    else:
        print("NO")

Submission status: Accepted

Solution code:
import math
def helon(x1, y1, x2, y2, x3, y3):
    a = math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
    b = math.sqrt((x3 - x2)**2 + (y3 - y2)**2)
    c = math.sqrt((x1 - x3)**2 + (y1 - y3)**2)
    s = (a + b + c) / 2
    return(math.sqrt(s * (s - a) * (s - b) * (s - c)))
    
while(True):
    try:
        input = map(float, raw_input().split())
        S = []
        S.append(helon(input[0], input[1], input[2], input[3], input[4], input[5]))
        S.append(helon(input[0], input[1], input[2], input[3], input[6], input[7]))
        S.append(helon(input[0], input[1], input[4], input[5], input[6], input[7]))
        S.append(helon(input[2], input[3], input[4], input[5], input[6], input[7]))
        if(math.fabs(S[0] - S[1] - S[2] - S[3]) < 1e-7):
            print("YES")
        else:
            print("NO")
    except Exception:
        break

Submission status: Accepted

Solution code:
import sys
def side(p1, p2, p3): return (p3[1]-p1[1])*(p2[0]-p1[0])-(p2[1]-p1[1])*(p3[0]-p1[0])>0
 
for s in sys.stdin:
  x = map(float, s.split())
  p1 = x[0:2]
  p2 = x[2:4]
  p3 = x[4:6]
  p0 = x[6:]
  print ["NO","YES"][(side(p1, p2, p0)==side(p2, p3, p0) and side(p2, p3, p0)==side(p3, p1, p0))]

Submission status: Accepted

Solution code:
import sys
def side(p1, p2, p3): return (p3[1]-p1[1])*(p2[0]-p1[0])-(p2[1]-p1[1])*(p3[0]-p1[0])>0
 
for s in sys.stdin:
  x = map(float, s.split())
  p1 = x[0:2]
  p2 = x[2:4]
  p3 = x[4:6]
  p0 = x[6:]
  print ["NO","YES"][(side(p1, p2, p0)==side(p2, p3, p0)==side(p3, p1, p0))]

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys

def dot_z(v1,v2):
  if v1[0]*v2[1]-v1[1]*v2[0] > 0:
    return 1
  else:
    return -1

def diff_p(p1,p2):
  return [ p2[0]-p1[0], p2[1]-p1[1] ]

for s in sys.stdin:
  d = map(float , s.split() )
  a = [d[0],d[1]]
  b = [d[2],d[3]]
  c = [d[4],d[5]]
  p = [d[6],d[7]]
  e1 = dot_z(diff_p(a,b),diff_p(b,p))
  e2 = dot_z(diff_p(b,c),diff_p(c,p))
  e3 = dot_z(diff_p(c,a),diff_p(a,p))
  if abs(e1+e2+e3) == 3 :
    print "YES"
  else:
    print "NO"

Submission status: Accepted

Solution code:
def S(x1,y1,x2,y2,x3,y3):
    return abs(x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2))/2.0

while True:
    try:
        x1,y1,x2,y2,x3,y3,xp,yp = map(float,raw_input().split())
        flag = S(x1,y1,x2,y2,xp,yp)+S(x1,y1,x3,y3,xp,yp)+S(x3,y3,x2,y2,xp,yp)-S(x1,y1,x2,y2,x3,y3) > 0.0000001
        print "NO" if flag else "YES"
    except:
        break

Submission status: Accepted

Solution code:
while True:
    try:
        x1,y1,x2,y2,x3,y3,xp,yp = map(float,raw_input().split())
        S = lambda x1,y1,x2,y2,x3=xp,y3=yp:abs(x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2))/2.0
        print "NO" if S(x1,y1,x2,y2)+S(x1,y1,x3,y3)+S(x3,y3,x2,y2)-S(x1,y1,x2,y2,x3,y3) > 0.0000001 else "YES"
    except:
        break

Submission status: Accepted

Solution code:
import sys
f = sys.stdin

def take2(iterable):
    i = iter(iterable)
    while True:
        yield next(i), next(i)
def cross(a, b):
    return a.real * b.imag - a.imag * b.real
def in_triangle(a, b, c, p):
    v1 = cross(a - b, b - p)
    v2 = cross(b - c, c - p)
    v3 = cross(c - a, a - p)
    return 0 < v1 * v2 and 0 < v2 * v3

for line in f:
    a, b, c, p = [x + y *1j for x, y in take2(map(float, line.split()))]
    print('YES' if in_triangle(a,b,c,p) else 'NO')

Submission status: Accepted

Solution code:
def S(x1,y1,x2,y2,x3,y3):
    return ((x2-x1)*(y3-y1)-(x3-x1)*(y2-y1))/2.0
import sys
for dataset in sys.stdin:
    x1,y1,x2,y2,x3,y3,xp,yp=map(float,dataset.split(" "))
    ABP=S(x1,y1,x2,y2,xp,yp)
    BCP=S(x2,y2,x3,y3,xp,yp)
    CAP=S(x3,y3,x1,y1,xp,yp)
    if ABP>0 and BCP>0 and CAP>0:
        print 'YES'
    elif ABP<0 and BCP<0 and CAP<0:
        print 'YES'
    else:
        print 'NO'

Submission status: Accepted

Solution code:
def CrossProduct(x1, y1, x2, y2, xp, yp):
	x2 -= x1
	xp -= x1
	y2 -= y1
	yp -= y1
	vec = (x2*yp-xp*y2)
	return True if vec > 0 else False

while True:
    try:
        x1, y1, x2, y2, x3, y3, xp, yp = map(float, raw_input().split())
    except EOFError:
        break
    if CrossProduct(x1, y1, x2, y2, xp, yp) == CrossProduct(x2, y2, x3, y3, xp, yp) == CrossProduct(x3, y3, x1, y1, xp, yp):
    	print 'YES'
    else:
    	print 'NO'

Submission status: Accepted

Solution code:
# coding: utf-8
while True:
    try:
        x1 ,y1, x2, y2, x3, y3, xp, yp = map(float,raw_input().split())
        # ?????????z????????????????¨?????????????
        c1 = (x2-x1) * (yp-y2) - (y2-y1) * (xp-x2)
        c2 = (x3-x2) * (yp-y3) - (y3-y2) * (xp-x3)
        c3 = (x1-x3) * (yp-y1) - (y1-y3) * (xp-x1)
        if all((c1>0,c2>0,c3>0)) or all((c1<0,c2<0,c3<0)):
            print 'YES'
        else:
            print 'NO'
    except EOFError:
        break

Submission status: Accepted

Solution code:
import sys
for x0,y0,x1,y1,x2,y2,xp,yp in[map(float,l.split()) for l in sys.stdin]:
	a=(x1-x0)*(y1-yp)-(y1-y0)*(x1-xp)
	b=(x2-x1)*(y2-yp)-(y2-y1)*(x2-xp)
	c=(x0-x2)*(y0-yp)-(y0-y2)*(x0-xp)
	print "YES" if a<0 and b<0 and c<0 or a>0 and b>0 and c>0 else "NO"

Submission status: Accepted

Solution code:
import sys
for a,b,c,d,e,f,g,h in[map(float,l.split()) for l in sys.stdin]:
	A=(c-a)*(d-h)-(d-b)*(c-g)
	B=(e-c)*(f-h)-(f-d)*(e-g)
	C=(a-e)*(b-h)-(b-f)*(a-g)
	print "YES"if A*B>0 and B*C>0 and C*A>0 else"NO"

Submission status: Accepted

Solution code:
import sys
for a,b,c,d,e,f,g,h in[map(float,l.split()) for l in sys.stdin]:print["NO","YES"][((c-a)*(d-h)-(d-b)*(c-g)>0)==((e-c)*(f-h)-(f-d)*(e-g)>0)==((a-e)*(b-h)-(b-f)*(a-g)>0)]

Submission status: Accepted

Solution code:
#!/usr/bin/env python
#-*- coding:utf-8 -*-

import sys
import math

for data in sys.stdin:
    x1, y1, x2, y2, x3, y3, xp, yp = list(map(float, data.split()))

    abV = (x1 - x2, y1 - y2)
    bpV = (x2 - xp, y2 - yp)

    bcV = (x2 - x3, y2 - y3)
    cpV = (x3 - xp, y3 - yp)

    caV = (x3 - x1, y3 - y1)
    apV = (x1 - xp, y1 - yp)

    c1 = abV[0] * bpV[1] - abV[1] * bpV[0]
    c2 = bcV[0] * cpV[1] - bcV[1] * cpV[0]
    c3 = caV[0] * apV[1] - caV[1] * apV[0]

    if (c1 < 0 and c2 < 0 and c3 < 0) or (c1 > 0 and c2 > 0 and c3 > 0):
        print("YES")
    else:
        print("NO")

Submission status: Accepted

Solution code:
while 1:
    try:
        x1,y1,x2,y2,x3,y3,xp,yp=map(float,raw_input().split())
        print 'YES' if ((x2-x1)*(y2-yp)-(y2-y1)*(x2-xp)>0)==((x3-x2)*(y3-yp)-(y3-y2)*(x3-xp)>0)==((x1-x3)*(y1-yp)-(y1-y3)*(x1-xp)>0) else 'NO'
    except:
        break

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-

def main():
    while True:
        try:
            ax,ay,bx,by,cx,cy,px,py=map(float,input().split())
            A=(bx-ax)*(py-ay)-(by-ay)*(px-ax)
            B=(cx-bx)*(py-by)-(cy-by)*(px-bx)
            C=(ax-cx)*(py-cy)-(ay-cy)*(px-cx)

            if ((A<=0)and(B<=0)and(C<=0))or((A>0)and(B>0)and(C>0)):
                print("YES")
            else:
                print("NO")

            

        except:
            break
            
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
while True:
	try:
		point = map(float,raw_input().split())
		z1 = (point[4] - point[2]) * (point[7] - point[3]) - (point[5] - point[3]) * (point[6] - point[2])
		z2 = (point[0] - point[4]) * (point[7] - point[5]) - (point[1] - point[5]) * (point[6] - point[4])
		z3 = (point[2] - point[0]) * (point[7] - point[1]) - (point[3] - point[1]) * (point[6] - point[0])
		
		if z1 > 0 and z2 > 0 and z3 > 0 or z1 < 0 and z2 < 0 and z3 < 0:
			print "YES"
		else:
			print "NO"
			
	except EOFError:
		break

Submission status: Accepted

Solution code:
while True:
    try:
        ax, ay, bx, by, cx, cy, px, py = map(float, input().split())
        a = (bx - ax) * (py - ay) - (by - ay) * (px - ax)
        b = (cx - bx) * (py - by) - (cy - by) * (px - bx)
        c = (ax - cx) * (py - cy) - (ay - cy) * (px - cx)
        if (a < 0 and b < 0 and c < 0) or (a > 0 and b > 0 and c > 0):
            print("YES")
        else:
            print("NO")
    except:
        break

Submission status: Accepted

Solution code:
def cross(x, y):
    return (x.conjugate() * y).imag

def inside_triangle(p, x, y, z):
    a = cross(y-x, p-y)
    b = cross(z-y, p-z)
    c = cross(x-z, p-x)
    if a*b > 0 and b*c > 0:
        return True
    return False

import sys

for line in sys.stdin:
    x1, y1, x2, y2, x3, y3, xp, yp = map(float, line.split())
    x = complex(x1, y1)
    y = complex(x2, y2)
    z = complex(x3, y3)
    p = complex(xp, yp)
    if inside_triangle(p, x, y, z):
        print('YES')
    else:
        print('NO')

Submission status: Accepted

Solution code:
#! -*- coding:utf-8 -*-
#????????????P????????????3???A,B,C????????£???????????????????§???¢???
#?????´?????????????????´???????????????????????????????????°?????????
#????????????????????????????????¨?????????
#?????????????????§?¨???????
import sys
for line in sys.stdin:
    #1:A,2:B,3:C
    ax,ay,bx,by,cx,cy,px,py = map(float,line.split())
    # AB
    abx = bx-ax
    aby = by-ay
    #BP
    bpx = px-bx
    bpy = py-by
    #BC
    bcx = cx-bx
    bcy = cy-by
    #CP
    cpx = px-cx
    cpy = py-cy
    #CA
    cax = ax-cx
    cay = ay-cy
    #AP
    apx = px-ax
    apy = py-ay

    #outer product
    c1 = abx * bpy - aby * bpx
    c2 = bcx * cpy - bcy * cpx
    c3 = cax * apy - cay * apx

    # print c1
    # print c2
    # print c3
    if (c1>0 and c2>0 and c3>0) or (c1<0 and c2<0 and c3<0):
        print "YES"
    else:
        print "NO"

Submission status: Accepted

Solution code:
import sys

def tri(x1,x2,y1,y2,z1,z2,p1,p2):
    a = (x1 - y1) * (y2 - p2) - (y1 - p1) * (x2 - y2)
    b = (y1 - z1) * (z2 - p2) - (z1 - p1) * (y2 - z2)
    c = (z1 - x1) * (x2 - p2) - (x1 - p1) * (z2 - x2)
    if(((a < 0) & (b < 0) & (c < 0)) | ((a > 0) & (b > 0) & (c > 0))):
        return 'YES'
    return 'NO'

ans = []
for i in sys.stdin:
    ans.append(tri(*map(float,i.split())))
print('\n'.join(map(str,ans)))

Submission status: Accepted

Solution code:
def r(x1, y1, x2, y2, x3, y3):
    return x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2) > 0

while True:
    try:
        line = input()
    except:
        break

    x1, y1, x2, y2, x3, y3, xp, yp = map(float, line.strip().split())

    abc = r(x1, y1, x2, y2, x3, y3)
    pab = r(xp, yp, x1, y1, x2, y2)
    pbc = r(xp, yp, x2, y2, x3, y3)
    pca = r(xp, yp, x3, y3, x1, y1)

    print('YES' if abc == pab == pbc == pca else 'NO')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys
import math

class Point_Class():
    def __init__(self, x, y):
        self.x = x
        self.y = y

def isIn(p1, p2, p3, pp):
    a = p2.y-p1.y
    b = p2.x-p1.x
    c = p2.x*p1.y-p1.x*p2.y
    d = p3.y-p2.y
    e = p3.x-p2.x
    f = p3.x*p2.y-p2.x*p3.y
    g = p1.y-p3.y
    h = p1.x-p3.x
    i = p1.x*p3.y-p3.x*p1.y
    if (a*pp.x-b*pp.y+c)*(a*p3.x-b*p3.y+c) < 0:
        return False
    if (d*pp.x-e*pp.y+f)*(d*p1.x-e*p1.y+f) < 0:
        return False
    if (g*pp.x-h*pp.y+i)*(g*p2.x-h*p2.y+i) < 0:
        return False
    return True


for line in sys.stdin:
    x1, y1, x2, y2, x3, y3, xp, yp = map(float, line.split())
    p1 = Point_Class(x1, y1)
    p2 = Point_Class(x2, y2)
    p3 = Point_Class(x3, y3)
    pp = Point_Class(xp, yp)
    print "YES" if isIn(p1, p2, p3, pp) else "NO"

Submission status: Accepted

Solution code:
import sys

def crossMulti(p1, p2):
    return p1[0] * p2[1] - p1[1] * p2[0]
           
lines = sys.stdin.readlines()
for line in lines:
    Zd = []
    x1, y1, x2, y2, x3, y3, xp, yp = map(float, line.split())
    Ps = [(x2-x1, y2-y1),(x3-x2, y3-y2),(x1-x3, y1-y3)]
    Px = [(xp-x1, yp-y1),(xp-x2, yp-y2),(xp-x3, yp-y3)]
    for p in range(3):
        Zd.append(crossMulti(Ps[p], Px[p]))
    Zd = [x > 0 for x in Zd]

    if (Zd[0] and Zd[1] and Zd[2]) or not(Zd[0] or Zd[1] or Zd[2]):
        print('YES')
    else:
        print('NO')

Submission status: Accepted

Solution code:
import math


class Triangle:
    def __init__(self, x1, y1, x2, y2, x3, y3):
        self.x1 = x1
        self.x2 = x2
        self.x3 = x3
        self.y1 = y1
        self.y2 = y2
        self.y3 = y3
        self.a = math.sqrt((x1-x2) ** 2 + (y1 - y2) ** 2)
        self.b = math.sqrt((x2-x3) ** 2 + (y2 - y3) ** 2)
        self.c = math.sqrt((x1-x3) ** 2 + (y1 - y3) ** 2)

    def get_acos_a(self):
        val = (-self.a ** 2 + self.b ** 2 + self.c ** 2) / (2 * self.b * self.c)
        return math.acos(val)


while(1):

    try:
        x1, y1, x2, y2, x3, y3, xp, yp = list(map(float, input().split()))
        t1 = Triangle(x1, y1, x2, y2, xp, yp)
        t2 = Triangle(x2, y2, x3, y3, xp, yp)
        t3 = Triangle(x3, y3, x1, y1, xp, yp)

        if 6.28318530 <= t1.get_acos_a() + t2.get_acos_a() + t3.get_acos_a() <= 6.28318531:
            print("YES")
        else:
            print("NO")

    except:
        break

Submission status: Accepted

Solution code:
import math


class Triangle:
    def __init__(self, x1, y1, x2, y2, x3, y3):
        self.x1 = x1
        self.x2 = x2
        self.x3 = x3
        self.y1 = y1
        self.y2 = y2
        self.y3 = y3
        self.a = math.sqrt((x1-x2) ** 2 + (y1 - y2) ** 2)
        self.b = math.sqrt((x2-x3) ** 2 + (y2 - y3) ** 2)
        self.c = math.sqrt((x1-x3) ** 2 + (y1 - y3) ** 2)

    def get_acos_a(self):
        val = (-self.a ** 2 + self.b ** 2 + self.c ** 2) / (2 * self.b * self.c)
        return math.acos(val)


while(1):

    try:
        x1, y1, x2, y2, x3, y3, xp, yp = list(map(float, input().split()))
        t1 = Triangle(x1, y1, x2, y2, xp, yp)
        t2 = Triangle(x2, y2, x3, y3, xp, yp)
        t3 = Triangle(x3, y3, x1, y1, xp, yp)

        def is_2pi(x):
            return math.fabs(x - math.pi*2) < 1.0e-10

        if is_2pi(t1.get_acos_a() + t2.get_acos_a() + t3.get_acos_a()):
            print("YES")
        else:
            print("NO")

    except:
        break

Submission status: Accepted

Solution code:
out=[]
while True:
	try:
		k=list(map(float,input().split(" ")))
	except:
		break

	O_x,O_y=k[0],k[1]
	A_x,A_y=k[2],k[3]
	B_x,B_y=k[4],k[5]
	P_x,P_y=k[6],k[7]

# P in triangle OAB
# iff  s+t<1 and s>0 and t>0 (OP=sOA+tOB)

	OA=(A_x-O_x,A_y-O_y)
	OB=(B_x-O_x,B_y-O_y)
	OP=(P_x-O_x,P_y-O_y)

	keisuu=1/( OA[0]*OB[1] - OA[1]*OB[0] )

	s=keisuu*(  OB[1]*OP[0]-OB[0]*OP[1] )
	t=keisuu*( -OA[1]*OP[0]+OA[0]*OP[1] )

	if s>0 and t>0 and s+t<1:
		out.append("YES")
	else:
		out.append("NO")

for i in out:
	print(i)

Submission status: Accepted

Solution code:
def Cramer(a11, a12, a13, a21, a22, a23):
	den = a11 * a22 - a12 * a21
	return (a13 * a22 - a12 * a23) / den, (a11 * a23 - a13 * a21) / den

while True:
	try:
		x1, y1, x2, y2, x3, y3, xp, yp = [eval(item) for item in input().split()]
		u, v = Cramer(x3 - x1, x2 - x1, xp - x1, y3 - y1, y2 - y1, yp - y1)
		print('YES' if u >= 0.0 and v >= 0.0 and u + v <= 1.0 else 'NO')
	except EOFError:
		break

Submission status: Accepted

Solution code:
import math
while True:
    try:
        x1, y1, x2, y2, x3, y3, xp, yp = map(float, input().split())
    except:
        break
    x = [x1, x2, x3, x1]
    y = [y1, y2, y3, y1]
    x = list(map(lambda i: i - xp, x))
    y = list(map(lambda i: i - yp, y))
    s = lambda a1, a2, b1, b2: abs(a1 * b2 - a2 * b1)
    S3 = sum(s(x[i], y[i], x[i + 1], y[i + 1]) for i in range(3))
    S = s(x[1] - x[0], y[1] - y[0], x[2] - x[0], y[2] - y[0])
    if S3 == S:
        print('YES')
    else:
        print('NO')

Submission status: Accepted

Solution code:
class point:
    def __init__(self, x, y):
        self.x = x
        self.y = y
    def sub(self, p):
        return point(self.x - p.x, self.y - p.y)

while 1:
    try:
        x1, y1, x2, y2, x3, y3, xp, yp = map(float, raw_input().split())
        A = point(x1, y1)
        B = point(x2, y2)
        C = point(x3, y3)
        P = point(xp, yp)

        AB = B.sub(A)
        BP = P.sub(B)
        BC = C.sub(B)
        CP = P.sub(C)
        CA = A.sub(C)
        AP = P.sub(A)

        c1 = AB.x * BP.y - AB.y * BP.x
        c2 = BC.x * CP.y - BC.y * CP.x
        c3 = CA.x * AP.y - CA.y * AP.x

        if((c1 > 0) and (c2 > 0) and (c3 > 0) or (c1 < 0) and (c2 < 0) and (c3 < 0)): print "YES"
        else: print "NO"
    except:
        break

Submission status: Accepted

Solution code:
import sys

def is_counter_clockwise(x1, y1, x2, y2, x3, y3):
    px = x2 - x1
    py = y2 - y1
    qx = x3 - x1
    qy = y3 - y1
    return px * qy - py * qx > 0

def is_in_triangle(x1, y1, x2, y2, x3, y3, xp, yp):
    if is_counter_clockwise(x1, y1, x2, y2, x3, y3):
        return is_counter_clockwise(x1, y1, x2, y2, xp, yp) and \
            is_counter_clockwise(x2, y2, x3, y3, xp, yp) and \
            is_counter_clockwise(x3, y3, x1, y1, xp, yp)
    else:
        return is_counter_clockwise(x1, y1, x3, y3, xp, yp) and \
            is_counter_clockwise(x3, y3, x2, y2, xp, yp) and \
            is_counter_clockwise(x2, y2, x1, y1, xp, yp)

for line in sys.stdin:
    x1, y1, x2, y2, x3, y3, xp, yp = map(float, line.split())
    if is_in_triangle(x1, y1, x2, y2, x3, y3, xp, yp):
        print("YES")
    else:
        print("NO")

Submission status: Accepted

Solution code:
import sys

for line in sys.stdin:
    x1, y1, x2, y2, x3, y3, xp, yp = map(float, line.split())
    AB = [x2-x1, y2-y1]
    BP = [xp-x2, yp-y2]
    BC = [x3-x2, y3-y2]
    CP = [xp-x3, yp-y3]
    CA = [x1-x3, y1-y3]
    AP = [xp-x1, yp-y1]
    c1 = AB[0] * BP[1] - AB[1] * BP[0]
    c2 = BC[0] * CP[1] - BC[1] * CP[0]
    c3 = CA[0] * AP[1] - CA[1] * AP[0]
    if (c1>0 and c2>0 and c3>0) or (c1<0 and c2<0 and c3<0):
        print 'YES'
    else:
        print 'NO'

Submission status: Accepted

Solution code:
def gai(a,b,c,d):
    S = a*d - b*c
    return(S)
while True:
    try:
        x1,y1,x2,y2,x3,y3,xp,yp  = map(float,input().split())
        if gai(x1 - x2,y1 - y2,x1 - xp,y1 - yp) < 0 and gai(x2 - x3,y2 - y3,x2 - xp,y2 - yp) < 0 and gai(x3 - x1,y3 - y1,x3 - xp,y3 - yp) < 0:
            print("YES")
        elif gai(x1 - x2,y1 - y2,x1 - xp,y1 - yp) > 0 and gai(x2 - x3,y2 - y3,x2 - xp,y2 - yp) > 0 and gai(x3 - x1,y3 - y1,x3 - xp,y3 - yp) > 0:
            print("YES")
        else:
            print("NO")
    except EOFError:
        break

Submission status: Accepted

Solution code:
while True:
    try:
        p = list(map(float,input().split()))
    except EOFError:
        break
    a = p[2] - p[0]
    b = p[4] - p[0]
    c = p[6] - p[0]
    d = p[3] - p[1]
    e = p[5] - p[1]
    f = p[7] - p[1]
    s = (c*e-b*f)/(a*e-b*d)
    t = (a*f-c*d)/(a*e-b*d)

    print("YES" if s>0 and s<1 and t>0 and t<1 and s+t<1 else "NO")

Submission status: Accepted

Solution code:
def getTriangleArea(x1, y1, x2, y2, x3, y3): # returns the area of triangle determined by provided 3 points
  ux = x2-x1
  uy = y2-y1
  vx = x3-x1
  vy = y3-y1
  return abs(ux*vy-vx*uy)/2

inputs=[]
while True:
  try:
    inputs.append(list(map(float,input().split())))
  except EOFError:
    break

for i in inputs:
  x1, y1, x2, y2, x3, y3, xp, yp = i
  if getTriangleArea(x1, y1, x2, y2, x3, y3)==getTriangleArea(x1, y1, x2, y2, xp, yp)+getTriangleArea(x2, y2, x3, y3, xp, yp)+getTriangleArea(x3, y3, x1, y1, xp, yp):
    print("YES")
  else:
    print("NO")

Submission status: Accepted

Solution code:
class vector(object):
    def __init__(self,a,b):
        self.x=b.x-a.x
        self.y=b.y-a.y
    @staticmethod
    def cross_product(a,b):
        return a.x*b.y-a.y*b.x
class vertex(object):
    def __init__(self,a):
        self.x=a[0]
        self.y=a[1]
class circle(object):
    def __init__(self,p,r):
        self.px=p.x
        self.py=p.y
        self.r=r
class triangle(object):
    def __init__(self,a,b,c):
        self.a=a
        self.b=b
        self.c=c
        import math
        self.ab=math.sqrt((self.a.x-self.b.x)**2+(self.a.y-self.b.y)**2)
        self.bc=math.sqrt((self.b.x-self.c.x)**2+(self.b.y-self.c.y)**2)
        self.ca=math.sqrt((self.c.x-self.a.x)**2+(self.c.y-self.a.y)**2)
        c=self.ab
        a=self.bc
        b=self.ca
        self.cosA=(b**2+c**2-a**2)/(2*b*c)
        self.cosB=(a**2+c**2-b**2)/(2*a*c)
        self.cosC=(b**2+a**2-c**2)/(2*b*a)
        self.sinA=math.sqrt(1-self.cosA**2)
        self.sinB=math.sqrt(1-self.cosB**2)
        self.sinC=math.sqrt(1-self.cosC**2)
        self.sin2A=2*self.sinA*self.cosA
        self.sin2B=2*self.sinB*self.cosB
        self.sin2C=2*self.sinC*self.cosC
    def area(self):
        import math
        s=(self.ab+self.bc+self.ca)/2
        S=math.sqrt(s*(s-self.ab)*(s-self.bc)*(s-self.ca))
        return S
    def circumscribed(self):
        R=self.ab/(2*self.sinC)
        px=(self.sin2A*self.a.x+self.sin2B*self.b.x+self.sin2C*self.c.x)/(self.sin2A+self.sin2B+self.sin2C)
        py=(self.sin2A*self.a.y+self.sin2B*self.b.y+self.sin2C*self.c.y)/(self.sin2A+self.sin2B+self.sin2C)
        px=round(px,3)
        py=round(py,3)
        R=round(R,3)
        p=vertex((px,py))
        return circle(p,R)
    def isin(self,p):
        AB=vector(self.a,self.b)
        BC=vector(self.b,self.c)
        CA=vector(self.c,self.a)
        AP=vector(self.a,p)
        BP=vector(self.b,p)
        CP=vector(self.c,p)
        if (vector.cross_product(AB,AP)>0 and vector.cross_product(BC,BP)>0 and vector.cross_product(CA,CP)>0)or(vector.cross_product(AB,AP)<0 and vector.cross_product(BC,BP)<0 and vector.cross_product(CA,CP)<0):
            return 'YES'
        else:return 'NO'
A=[]
B=[]
C=[]
p=[]
import sys
for line in sys.stdin:
    a,b,c,d,e,f,g,h=list(map(float,line.split()))
    A.append(vertex((a,b)))
    B.append(vertex((c,d)))
    C.append(vertex((e,f)))
    p.append(vertex((g,h)))
for i in range(len(A)):
    Triangle=triangle(A[i],B[i],C[i])
    print(Triangle.isin(p[i]))

Submission status: Accepted

Solution code:
def f(a,b,c,d,e,f,g,h):return ((a-c)*(f-b)+(b-d)*(a-e))*((a-c)*(h-b)+(b-d)*(a-g))
while 1:
    try:x1,y1,x2,y2,x3,y3,xp,yp=map(float,input().split())
    except:break
    x=(x1+x2+x3)/3
    y=(y1+y2+y3)/3
    print(['YES','NO'][f(x1,y1,x2,y2,xp,yp,x,y)<0 or f(x1,y1,x3,y3,xp,yp,x,y)<0 or f(x2,y2,x3,y3,xp,yp,x,y)<0])

Submission status: Accepted

Solution code:
import sys

def to_f(e):
  return float(e)

while True:
  line = sys.stdin.readline()
  if not line: break
  x1, y1, x2, y2, x3, y3, xp, yp = map(to_f, line.split(" "))
  a = (x2-x1)*(y3-y1)-(x3-x1)*(y2-y1)
  b = (xp-x1)*(y3-y1)-(x3-x1)*(yp-y1)
  c = (x2-x1)*(yp-y1)-(xp-x1)*(y2-y1)
  s = b/a
  t = c/a
  if s>0 and t>0 and 0<s+t and s+t<1:
    print("YES")
  else:
    print("NO")

Submission status: Accepted

Solution code:
import math
from sys import stdin

def length(u,v):
    x0=u[0]
    y0=u[1]
    x1=v[0]
    y1=v[1]
    return(math.sqrt(((x1-x0)**2+(y1-y0)**2)))

def s(a,b,c):
    l=length(a,b)
    m=length(b,c)
    n=length(c,a)
    o = (l+m+n)/2.0
    p=o*(o-l)*(o-m)*(o-n)
    q=math.sqrt(p)
    return(q)

if __name__ == "__main__": 
   eps=1e-5
   for line in stdin:
        v=list(map(float,line.split()))
        a=(v[0],v[1])
        b=(v[2],v[3])
        c=(v[4],v[5])
        p=(v[6],v[7])
        s0=s(a,b,c)
        s1=s(p,a,b)
        s2=s(p,b,c)
        s3=s(p,c,a)
        if abs(s0 - (s1+s2+s3))< eps:
            print("YES")
        else:
            print("NO")

Submission status: Accepted

Solution code:
import sys

def sameside(x1, y1, x2, y2, ax, ay, bx, by):
    if x1 != x2:
        aupper = (ay > (y1-y2)/(x1-x2) * (ax-x1) + y1)
        bupper = (by > (y1-y2)/(x1-x2) * (bx-x1) + y1)
    else:
        aupper = ax < x1
        bupper = bx < x1
    return aupper == bupper

for line in sys.stdin:
    x1, y1, x2, y2, x3, y3, xp, yp = list(map(float, line.split()))
    if sameside(x1, y1, x2, y2, x3, y3, xp, yp) and sameside(x2, y2, x3, y3, x1, y1, xp, yp) and sameside(x3, y3, x1, y1, x2, y2, xp, yp):
        print("YES")
    else:
        print("NO")

Submission status: Accepted

Solution code:
def check(x1, y1, x2, y2, xp, yp):
    return ((y1 > yp) != (y2 > yp)) and (xp - x1 < (x2 - x1) * (yp - y1) / (y2 - y1))


while True:
    try:
        x1, y1, x2, y2, x3, y3, xp, yp = map(float, input().split())
    except:
        break
    print('YES' if (check(x1, y1, x2, y2, xp, yp) +
                    check(x2, y2, x3, y3, xp, yp) +
                    check(x3, y3, x1, y1, xp, yp)) & 1 else 'NO')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys
import os
import math

def cross(a, b):
    ax = a[0]
    ay = a[1]
    bx = b[0]
    by = b[1]
    return ax * by - ay * bx


for s in sys.stdin:
    s = s.strip()
    ax, ay, bx, by, cx, cy, px, py = map(float, s.split())
    # point A, B, C, P
    AP = (px - ax, py - ay)
    BP = (px - bx, py - by)
    CP = (px - cx, py - cy)

    BA = (ax - bx, ay - by)
    AC = (cx - ax, cy - ay)
    CB = (bx - cx, by - cy)

    v0 = cross(BP, BA)
    v1 = cross(CP, CB)
    v2 = cross(AP, AC)

    if v0 > 0 and v1 > 0 and v2 > 0:
        print('YES')
    elif v0 < 0 and v1 < 0 and v2 < 0:
        print('YES')
    else:
        print('NO')

Submission status: Accepted

Solution code:
import math

def tri(x1, y1, x2, y2, x3, y3):
    return math.fabs((x2-x1)*(y3-y1) - (y2-y1)*(x3-x1)) / 2

while True:
    try:
        x1, y1, x2, y2, x3, y3, xp, yp = map(float, input().split())
    except:
        break
    abc = tri(x1, y1, x2, y2, x3, y3)
    abp = tri(x1, y1, x2, y2, xp, yp)
    acp = tri(x1, y1, x3, y3, xp, yp)
    bcp = tri(x2, y2, x3, y3, xp, yp)
    x, y = int(abc*pow(10, 5)), int((abp+acp+bcp)*pow(10, 5))
    print("YES" if x >= y else "NO")

Submission status: Accepted

Solution code:


while 1:
    try:
        x1, y1, x2, y2, x3, y3, px, py = map(float, input().split())
        a = (x2-x1) * (py-y1) - (y2-y1) * (px-x1)
        b = (x3-x2) * (py-y2) - (y3-y2) * (px-x2)
        c = (x1-x3) * (py-y3) - (y1-y3) * (px-x3)
        if (a < 0 and b < 0 and c < 0) or (a > 0 and b > 0 and c > 0):
            print("YES")
        else:
            print("NO")
    except:
        break;

Submission status: Accepted

Solution code:
import math


def tri(x1, y1, x2, y2, x3, y3):
    return math.fabs((x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1)) / 2

while True:
    try:
        x1, y1, x2, y2, x3, y3, x, y = map(float, input().split())
    except:
        break
    abc = tri(x1, y1, x2, y2, x3, y3)
    abp = tri(x1, y1, x2, y2, x, y)
    acp = tri(x1, y1, x3, y3, x, y)
    bcp = tri(x2, y2, x3, y3, x, y)
    x, y = int(abc * pow(10, 5)), int((abp + acp + bcp) * pow(10, 5))
    print("YES" if x >= y else "NO")

Submission status: Accepted

Solution code:
from decimal import Decimal as D
import sys

def S(P,Q,R):
    #      R
    #
    #P
    #          Q

    PQ=[Q[0]-P[0],Q[1]-P[1]]
    PR=[R[0]-P[0],R[1]-P[1]]
    s=PQ[0]*PR[1]-PQ[1]*PR[0]
    return s

while True:
    try:
        x1,y1,x2,y2,x3,y3,xp,yp=[D(i) for i in input().split(" ")]
        A=[x1,y1]
        B=[x2,y2]
        C=[x3,y3]
        P=[xp,yp]

        if (S(A,B,P)>0 and S(B,C,P)>0 and S(C,A,P)>0) or (S(A,B,P)<0 and S(B,C,P)<0 and S(C,A,P)<0):
            print("YES")
        else:
            print("NO")
    except EOFError:
        sys.exit()

Submission status: Accepted

Solution code:
import sys

def isleft(ox, oy, ax, ay, px, py):
    oax, oay = ax - ox, ay - oy
    opx, opy = px - ox, py - oy
    if oax * opy > oay * opx:
        return 1
    else:
        return 0

for line in sys.stdin:
    x1, y1, x2, y2, x3, y3, xp, yp = map(float, line.split())
#    A, B, C, P = (x1, y1), (x2, y2), (x3, y3), (xp, yp)
#    if isleft(*A, *B, *P) == isleft(*B, *C, *P) == isleft(*C, *A, *P):
    if isleft(x1, y1, x2, y2, xp, yp) == isleft(x2, y2, x3, y3, xp, yp) == isleft(x3, y3, x1, y1, xp, yp):
        print("YES")
    else:
        print("NO")

Submission status: Accepted

Solution code:
import fileinput


class Vector2D:
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def dot(self, vec2d):
        return (self.x * vec2d.y) - (self.y * vec2d.x)


for line in fileinput.input():
    x1, y1, x2, y2, x3, y3, xp, yp = [float(r) for r in line.split()]
    v1To2 = Vector2D(x2 - x1, y2 - y1)
    v2To3 = Vector2D(x3 - x2, y3 - y2)
    v3To1 = Vector2D(x1 - x3, y1 - y3)
    v1ToP = Vector2D(xp - x1, yp - y1)
    v2ToP = Vector2D(xp - x2, yp - y2)
    v3ToP = Vector2D(xp - x3, yp - y3)

    if (v1To2.dot(v1ToP) < 0 and v2To3.dot(v2ToP) < 0 and v3To1.dot(v3ToP) < 0) or (v1To2.dot(v1ToP) > 0 and v2To3.dot(v2ToP) > 0 and v3To1.dot(v3ToP) > 0):
        print("YES")
    else:
        print("NO")

Submission status: Accepted

Solution code:
# Aizu Problem 0012: Point in Triangle
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


def point_in_triangle(trig, x, y):
    x1, y1, x2, y2, x3, y3 = trig[:]
    a = ((y2 - y3)*(x - x3) + (x3 - x2)*(y - y3)) / ((y2 - y3)*(x1 - x3) + (x3 - x2)*(y1 - y3))
    b = ((y3 - y1)*(x - x3) + (x1 - x3)*(y - y3)) / ((y2 - y3)*(x1 - x3) + (x3 - x2)*(y1 - y3))
    c = 1 - a - b
    return 0 < a < 1 and 0 < b < 1 and 0 < c < 1

          
for line in sys.stdin:
    inp = [float(_) for _ in line.split()]
    print("YES" if point_in_triangle(inp[:6], inp[6], inp[7]) else "NO")