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: Runtime Error

Solution code:
def dot(a, b):
    return (a.real*b.real - a.imag*b.imag)
def cross(a, b):
    return (a.real*b.imag - a.imag*b.real)

EPS = 10**(-7)

def isIntersectedLS(a1, a2, b1, b2):
    return ((cross(a2-a1, b1-a1) * cross(a2-a1, b2-a1)) < EPS and
            (cross(b2-b1, a1-b1) * cross(b2-b1, a2-b1)) < EPS)

while 1:
    try:
        x,y = [[0. for i in xrange(3)] for j in xrange(2)]
        a = []
        xp,yp = (0,0)
        line = raw_input().split()
        if line == []: break
        x[0],y[0],x[1],y[1],x[2],y[2],z[0],z[1] = map(float, line)
        for i in xrange(3):
            a.append((x[i]+(y[i])*1j))
        c = (sum(x)/3)+(sum(y)/3)*1j
        p = z[0]+z[1]*1j
           
        for i in xrange(3):
            #print a, c, p
            if isIntersectedLS(a[i-1], a[i], c, p) is True:
                print "NO"
                break
        else:
            print "YES"
           
    except EOFError:
        break

Submission status: Runtime Error

Solution code:
def dot(a, b):
    return (a.real*b.real - a.imag*b.imag)
def cross(a, b):
    return (a.real*b.imag - a.imag*b.real)

EPS = 10**(-7)

def isIntersectedLS(a1, a2, b1, b2):
    return ((cross(a2-a1, b1-a1) * cross(a2-a1, b2-a1)) < EPS and
            (cross(b2-b1, a1-b1) * cross(b2-b1, a2-b1)) < EPS)

while 1:
    try:
        x,y = [[0. for i in xrange(3)] for j in xrange(2)]
        a = []
        z = (0,0)
        line = raw_input().split()
        if line == []: break
        x[0],y[0],x[1],y[1],x[2],y[2],z[0],z[1] = map(float, line)
        for i in xrange(3):
            a.append((x[i]+(y[i])*1j))
        c = (sum(x)/3)+(sum(y)/3)*1j
        p = z[0]+z[1]*1j
           
        for i in xrange(3):
            #print a, c, p
            if isIntersectedLS(a[i-1], a[i], c, p) is True:
                print "NO"
                break
        else:
            print "YES"
           
    except EOFError:
        break

Submission status: Runtime Error

Solution code:
def heron(a,b,c):
    s = 0.5*(a+b+c)
    return (s*(s-a)*(s-b)*(s-c))**0.5

while True:
    try:
        x = map(float, raw_input().split(' '))

        ab = ((x[0]-x[2])**2 +(x[1]-x[3])**2)**0.5
        bc = ((x[2]-x[4])**2 +(x[3]-x[5])**2)**0.5
        ca = ((x[4]-x[0])**2 +(x[5]-x[1])**2)**0.5
        area_abc = heron(ab,bc,ca)


        oa = ((x[0]-x[6])**2 +(x[1]-x[7])**2)**0.5
        ob = ((x[2]-x[6])**2 +(x[3]-x[7])**2)**0.5
        oc = ((x[4]-x[6])**2 +(x[5]-x[7])**2)**0.5

        area_oab = heron(ab,oa,ob)
        area_obc = heron(bc,ob,oc)
        area_oca = heron(ca,oc,oa)
        area_sum = area_oab+area_obc+area_oca

        if round(area_abc,2) < round(area_sum,2):
            print 'NO'
        else:
            print 'YES'

    except EOFError:
        break

Submission status: Runtime Error

Solution code:
def heron(a,b,c):
    s = 0.5*(a+b+c)
    return (s*(s-a)*(s-b)*(s-c))**0.5

while True:
    try:
        x = map(float, raw_input().split(' '))

        ab = ((x[0]-x[2])**2 +(x[1]-x[3])**2)**0.5
        bc = ((x[2]-x[4])**2 +(x[3]-x[5])**2)**0.5
        ca = ((x[4]-x[0])**2 +(x[5]-x[1])**2)**0.5
        area_abc = heron(ab,bc,ca)


        oa = ((x[0]-x[6])**2 +(x[1]-x[7])**2)**0.5
        ob = ((x[2]-x[6])**2 +(x[3]-x[7])**2)**0.5
        oc = ((x[4]-x[6])**2 +(x[5]-x[7])**2)**0.5

        area_oab = heron(ab,oa,ob)
        area_obc = heron(bc,ob,oc)
        area_oca = heron(ca,oc,oa)
        area_sum = area_oab+area_obc+area_oca

        if round(area_abc) < round(area_sum):
            print 'NO'
        else:
            print 'YES'

    except EOFError:
        break

Submission status: Runtime Error

Solution code:

while True:
    try:
        x1,y1,x2,y2,x3,y3,px,py = map(float,raw_input().split(' '))
            
        v1 = [x1-px,y1-py]
        v2 = [x2-px,y2-py]
        v3 = [x3-px,y3-py]
        
        v12 =[v1[0]+v2[0],v1[1]+v2[1]]
        
        if v12[0]*v3[0]+v12[1]*v3[1] < 0:
            print 'YES'
        else:
            print 'NO'
    except EOFError:
        break

Submission status: Runtime Error

Solution code:
while True:
    try:
        x1,y1,x2,y2,x3,y3,px,py = map(float,raw_input().split(' '))
            
        v1 = [x1-px,y1-py]
        v2 = [x2-px,y2-py]
        v3 = [x3-px,y3-py]
        
        v12 =[v1[0]+v2[0],v1[1]+v2[1]]
        
        if v12[0]*v3[0]+v12[1]*v3[1] < 0:
            print 'YES'
        else:
            print 'NO'


    except EOFError:
        break

Submission status: Runtime Error

Solution code:
while True:
    try:
        x1,y1,x2,y2,x3,y3,px,py = map(float,raw_input().split())
        v1 = [x1-px,y1-py]
        v2 = [x2-px,y2-py]
        v3 = [x3-px,y3-py]
        v12 =[v1[0]+v2[0],v1[1]+v2[1]]
        if v12[0]*v3[0]+v12[1]*v3[1] < 0:
            print 'YES'
        else:
            print 'NO'

    except EOFError:
        break

Submission status: Runtime Error

Solution code:
def checker(x1,y1,x2,y2,xp,yp):
	vec = (x2 - x1) * (yp - y1) - (y2 - y1) * (xp - x1)
	if vec > 0:
		return 1
	elif vec < 0:
		return -1

while True:
	try:
		x1,y1,x2,y2,x3,y3,xp,yp = map(float,raw_input().split())
	except EOFError:
		break
	r = checker(x1,y1,x2,y2,xp,yp)
	r += checker(x2, y2, x3, y3, xp, yp)
	r += checker(x3, y3, x1, y1, xp, yp)
	if r == 3 or r == -3:
		print("YES")
	else:
		print("NO")

Submission status: Runtime Error

Solution code:
def checker(x1,y1,x2,y2,xp,yp):
	vec = (x2 - x1) * (yp - y1) - (y2 - y1) * (xp - x1)
	if vec > 0:
		return 1
	elif vec < 0:
		return -1

while True:
	try:
		x1,y1,x2,y2,x3,y3,xp,yp = map(float,raw_input().split())
		r = checker(x1,y1,x2,y2,xp,yp)
		r += checker(x2, y2, x3, y3, xp, yp)
		r += checker(x3, y3, x1, y1, xp, yp)
		if r == 3 or r == -3:
			print("YES")
		else:
			print("NO")
	except EOFError:
		break

Submission status: Runtime Error

Solution code:
global r

def checker(x1,y1,x2,y2,xp,yp):
	vec = (x2 - x1) * (yp - y1) - (y2 - y1) * (xp - x1)
	if vec > 0:
		return 1
	elif vec < 0:
		return -1

while True:
	try:
		x1,y1,x2,y2,x3,y3,xp,yp = map(float,raw_input().split())
		r = 0
		r = r + checker(x1,y1,x2,y2,xp,yp)
		r = r + checker(x2, y2, x3, y3, xp, yp)
		r = r + checker(x3, y3, x1, y1, xp, yp)
		if r == 3 or r == -3:
			print("YES")
		else:
			print("NO")
	except EOFError:
		break

Submission status: Runtime Error

Solution code:
global r

def checker(x1,y1,x2,y2,xp,yp):
	vec = (x2 - x1) * (yp - y1) - (y2 - y1) * (xp - x1)
	if vec > 0:
		return int(1)
	elif vec < 0:
		return int(-1)

while True:
	try:
		x1,y1,x2,y2,x3,y3,xp,yp = map(float,raw_input().split())
		r = 0
		r += checker(x1,y1,x2,y2,xp,yp)
		print r
		r += checker(x2, y2, x3, y3, xp, yp)
		print r
		r += checker(x3, y3, x1, y1, xp, yp)
		print r
		if r == 3 or r == -3:
			print("YES")
		else:
			print("NO")
	except EOFError:
		break

Submission status: Runtime Error

Solution code:
global r

def checker(x1,y1,x2,y2,xp,yp):
	vec = (x2 - x1) * (yp - y1) - (y2 - y1) * (xp - x1)
	if vec > 0:
		return int(1)
	elif vec < 0:
		return int(-1)

if __name__ == '__main__':
	while True:
		try:
			x1,y1,x2,y2,x3,y3,xp,yp = map(float,raw_input().split())
			r = 0
			r += checker(x1,y1,x2,y2,xp,yp)
			r += checker(x2, y2, x3, y3, xp, yp)
			r += checker(x3, y3, x1, y1, xp, yp)
			if r == 3 or r == -3:
				print("YES")
			else:
				print("NO")
		except EOFError:
			break

Submission status: Runtime Error

Solution code:
global r

def checker(x1,y1,x2,y2,xp,yp):
	vec = (x2 - x1) * (yp - y1) - (y2 - y1) * (xp - x1)
	if vec > 0:
		return int(1)
	elif vec < 0:
		return int(-1)

if __name__ == '__main__':
	while True:
		try:
			x1,y1,x2,y2,x3,y3,xp,yp = map(float,raw_input().split())
			r = 0
			r += int(checker(x1,y1,x2,y2,xp,yp))
			r += int(checker(x2, y2, x3, y3, xp, yp))
			r += int(checker(x3, y3, x1, y1, xp, yp))
			if r == 3 or r == -3:
				print("YES")
			else:
				print("NO")
		except EOFError:
			break

Submission status: Runtime Error

Solution code:
def checker(x1,y1,x2,y2,xp,yp):
	r = 0
	vec = (x2 - x1) * (yp - y1) - (y2 - y1) * (xp - x1)
	if vec > 0:
		r = 1
		return r
	elif vec < 0:
		r = -1
		return r

if __name__ == '__main__':
	while True:
		try:
			x1,y1,x2,y2,x3,y3,xp,yp = map(float,raw_input().split())
			r = 0
			r += int(checker(x1,y1,x2,y2,xp,yp))
			r += int(checker(x2, y2, x3, y3, xp, yp))
			r += int(checker(x3, y3, x1, y1, xp, yp))
			if r == 3 or r == -3:
				print("YES")
			else:
				print("NO")
		except EOFError:
			break

Submission status: Runtime Error

Solution code:
while True:
    try:
        x1,y1,x2,y2,x3,y3,xp,yp = map(float, raw_input().split())
        a = (x1-x2)**2+(y1-y2)**2
        b = (x1-x3)**2+(y1-y3)**2
        c = (x2-x3)**2+(y2-y3)**2
        xa = (x3-xp)**2+(y3-yp)**2
        xb = (x2-xp)**2+(y2-yp)**2
        xc = (x1-xp)**2+(y1-yp)**2
        cosa = (a-b+c)/(2*math.sqrt(b)*math.sqrt(c))
        cosb = (b-a+c)/(2*math.sqrt(a)*math.sqrt(c))
        cosc = (c-a+b)/(2*math.sqrt(a)*math.sqrt(b))
        cos1 = (xc-xa+xc)/(2*math.sqrt(xa)*math.sqrt(b))
        cos2 = (xa-c+xb)/(2*math.sqrt(xb)*math.sqrt(c))
        cos3 = (xb-a+xc)/(2*math.sqrt(xc)*math.sqrt(a))
#       cos4 = (a-b+c)/(2*math.sqrt(xa)*math.sqrt(c))
#      cos5 = (a-b+c)/(2*math.sqrt(xb)*math.sqrt(a))
#      cos6 = (a-b+c)/(2*math.sqrt(xc)*math.sqrt(b))
        
        if cos1<cosa or cos2<cosb or cos3<cosc:
            print "YES"
        print "YES"
        else:
            print "NO"
    except:
        break