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:
def checker(x1,y1,x2,y2,xp,yp):
	r = 0
	vec = (x2 - x1) * (yp - y1) - (y2 - y1) * (xp - x1)
	if vec > 0:
		r = 1
	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: Accepted

Solution code:
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin
from operator import attrgetter
from collections import namedtuple

Point = namedtuple('Point', 'x y')

def linear(p1, p2):
    gradient = (p1.y - p2.y) / (p1.x - p2.x)
    y_intercept = p1.y - gradient * p1.x
    return lambda x: gradient * x + y_intercept

def takeout(seq):
    gen = (Point(next(seq), next(seq)) for _ in xrange(3))
    for p in sorted(gen, key=attrgetter('x')):
        yield p
    yield Point(next(seq), next(seq))

for line in stdin:
    A, B, C, P = takeout(float(s) for s in line.split())
    assert A.x <= B.x <= C.x
    if P.x <= A.x or C.x <= P.x:
        print('NO')
        continue
    if A.x == B.x or B.x <= P.x <= C.x:
        L = (linear(B, C), linear(A, C))
    elif B.x == C.x or A.x <= P.x <= B.x:
        L = (linear(A, B), linear(A, C))
    else:
        print('NO')
        continue

    y1, y2 = sorted(f(P.x) for f in L)
    if y1 < P.y < y2:
        print('YES')
    else:
        print('NO')

Submission status: Accepted

Solution code:
from math import sqrt
dis = lambda x1,y1,x2,y2: sqrt((x1-x2)**2+(y1-y2)**2)
def heron(a,b,c):
    s = (a+b+c)*1.0/2
    return sqrt(s*(s-a)*(s-b)*(s-c))
while True:
    try:
        x1,y1,x2,y2,x3,y3,xp,yp = map(float,raw_input().split())
        a,b,c = dis(x1,y1,x2,y2),dis(x1,y1,x3,y3),dis(x3,y3,x2,y2)
        d,e,f = dis(x1,y1,xp,yp),dis(xp,yp,x2,y2),dis(xp,yp,x3,y3)
        AnsS = heron(a,b,c)
        FakS = heron(a,e,d)+heron(e,c,f)+heron(d,b,f)
        q1,q2 = str(AnsS),str(FakS)
        Ans = "YES" if q1 == q2 else "NO"
        print Ans
    except EOFError: break

Submission status: Accepted

Solution code:
import sys


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



def direction_of_rotation(p1, p2, p3):
    d = p1.x * (p2.y - p3.y) + p2.x * (p3.y - p1.y) + p3.x * (p1.y - p2.y)
    if d < 0:
        direction = 'right'
    else:
        direction = 'left'
    return direction



#input_file = open(sys.argv[1], "r")

#for line in input_file:
for line in sys.stdin:
    a = map((lambda x: float(x)), line.split(' '))
    p1 = Point(a[0], a[1])
    p2 = Point(a[2], a[3])
    p3 = Point(a[4], a[5])
    p  = Point(a[6], a[7])
    d1 = direction_of_rotation(p, p1, p2)
    d2 = direction_of_rotation(p, p2, p3)
    d3 = direction_of_rotation(p, p3, p1)
    if d1 == d2 and d1 == d3:
        print "YES"
    else:
        print "NO"

Submission status: Accepted

Solution code:
import sys

class Point(object):
    def __init__(self, x, y):
        self.x = x
        self.y = y
    def isLeft(self, vector):
        tmpVector = DirectedVector(vector.start, self)
        sin = tmpVector * vector
        if sin > 0:
            return True
        else:
            return False

class DirectedVector(object):
    def __init__(self, start, end):
        self.start = start
        self.end = end
    @property
    def x(self):
        return self.end.x - self.start.x
    @property
    def y(self):
        return self.end.y - self.start.y
    def __mul__(self, other):
        return self.x * other.y - self.y * other.x

def getDataSets():
    for line in sys.stdin.readlines():
        line = line.strip()
        x1, y1, x2, y2, x3, y3, xp, yp = [float(x) for x in line.split()]
        p1 = Point(x1, y1)
        p2 = Point(x2, y2)
        p3 = Point(x3, y3)
        px = Point(xp, yp)
        yield p1, p2, p3, px

def main():
    for p1, p2, p3, px in getDataSets():
        evaluate = [
                px.isLeft(DirectedVector(p1, p2)),
                px.isLeft(DirectedVector(p2, p3)),
                px.isLeft(DirectedVector(p3, p1)),
                ]
        if(all(evaluate) or not any(evaluate)):
            print 'YES'
        else:
            print 'NO'

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def side(p1, p2, p3):
    return (p3[1]-p1[1])*(p2[0]-p1[0])-(p2[1]-p1[1])*(p3[0]-p1[0])>0

while True:
    try:
        x = map(float, raw_input().split())
        p1 = x[0:2]
        p2 = x[2:4]
        p3 = x[4:6]
        p0 = x[6:]
        if (side(p1, p2, p0)==side(p2, p3, p0) and side(p2, p3, p0)==side(p3, p1, p0)):
            print "YES"
        else:
            print "NO"
    except:
        break

Submission status: Accepted

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

Submission status: Accepted

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

import sys


def prod2d(vec1, vec2):
    return vec1[0]*vec2[1] - vec1[1]*vec2[0]

lineNumber = 0
#for line in [ "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"]:
for line in sys.stdin.readlines():
    lineNumber += 1

    # get data
    List = map(float, line.strip().split())

    # set data
    nodes = [ [List[0], List[1]], [List[2], List[3]], [List[4], List[5]] ]
    point = [List[6], List[7]]

    
    ABvec = [ nodes[1][0] - nodes[0][0], nodes[1][1] - nodes[0][1] ]
    BCvec = [ nodes[2][0] - nodes[1][0], nodes[2][1] - nodes[1][1] ]
    CAvec = [ nodes[0][0] - nodes[2][0], nodes[0][1] - nodes[2][1] ]
    APvec = [ point[0] - nodes[0][0], point[1] - nodes[0][1] ]
    BPvec = [ point[0] - nodes[1][0], point[1] - nodes[1][1] ]
    CPvec = [ point[0] - nodes[2][0], point[1] - nodes[2][1] ]

    a = prod2d(CAvec, APvec)
    b = prod2d(ABvec, BPvec)
    c = prod2d(BCvec, CPvec)

    if   a > 0 and b > 0 and c > 0: print "YES"
    elif a < 0 and b < 0 and c < 0: print "YES"
    else                          : print "NO"

Submission status: Accepted

Solution code:
import math
while True:
    try:
        x1,y1,x2,y2,x3,y3,xp,yp = map(float, raw_input().split())
        a = math.sqrt((x1-x2)**2+(y1-y2)**2)
        b = math.sqrt((x1-x3)**2+(y1-y3)**2)
        c = math.sqrt((x2-x3)**2+(y2-y3)**2)
        xa = math.sqrt((x3-xp)**2+(y3-yp)**2)
        xb = math.sqrt((x2-xp)**2+(y2-yp)**2)
        xc = math.sqrt((x1-xp)**2+(y1-yp)**2)
        s = (a+b+c)/2
        sa = (a+xb+xc)/2
        sb = (b+xa+xc)/2
        sc = (c+xa+xb)/2
        ss = math.sqrt(s*(s-a)*(s-b)*(s-c))
        ssa = math.sqrt(sa*(sa-a)*(sa-xb)*(sa-xc))
        ssb = math.sqrt(sb*(sb-xa)*(sb-b)*(sb-xc))
        ssc = math.sqrt(sc*(sc-xa)*(sc-xb)*(sc-c))
        
        if ssa+ssb+ssc - ss > 0.0000001:
            print "NO"
        else:
            print "YES"
    except:
        break

Submission status: Accepted

Solution code:
import math
def S(a,b,c):
	s = (a+b+c)/2
	return math.sqrt(s*(s-a)*(s-b)*(s-c))
	
while True:
	try:
		x1,y1,x2,y2,x3,y3,xp,yp = map(float, raw_input().split())
		a = math.sqrt((x1-x2)**2+(y1-y2)**2)
		b = math.sqrt((x1-x3)**2+(y1-y3)**2)
		c = math.sqrt((x2-x3)**2+(y2-y3)**2)
		xa = math.sqrt((x3-xp)**2+(y3-yp)**2)
		xb = math.sqrt((x2-xp)**2+(y2-yp)**2)
		xc = math.sqrt((x1-xp)**2+(y1-yp)**2)
		if S(a,xb,xc)+S(b,xc,xa)+S(c,xa,xb)-S(a,b,c) > 0.0000001:
			print "NO"
		else:
			print "YES"
	except:
		break

Submission status: Accepted

Solution code:
import math

def L(x1,y1,x2,y2):
	return math.sqrt((x1-x2)**2+(y1-y2)**2)
	
def S(a,b,c):
	s=(a+b+c)/2
	return math.sqrt(s*(s-a)*(s-b)*(s-c))
	
while True:
    try:
        x1,y1,x2,y2,x3,y3,xp,yp = map(float, raw_input().split())
        a  = L(x1,y1,x2,y2)
        b  = L(x1,y1,x3,y3)
        c  = L(x2,y2,x3,y3)
        pa = L(x3,y3,xp,yp)
        pb = L(x2,y2,xp,yp)
        pc = L(x1,y1,xp,yp)
        if S(a,pb,pc)+S(b,pc,pa)+S(c,pa,pb)-S(a,b,c) > 0.0000001:
            print "NO"
        else:
            print "YES"
    except:
        break

Submission status: Accepted

Solution code:
import sys

def c(x1, y1, x2, y2, x, y):
  return (y2 - y1)*(x - x1) - (x2 - x1)*(y - y1)

for str in sys.stdin:
  x1,y1,x2,y2,x3,y3,xp,yp = map(float, str.split(' '))
  gx, gy = (x1 + x2 + x3)/3, (y1 + y2 + y3)/3

  r1 = c(x1, y1, x2, y2, gx, gy)*c(x1, y1, x2, y2, xp, yp) > 0
  r2 = c(x2, y2, x3, y3, gx, gy)*c(x2, y2, x3, y3, xp, yp) > 0
  r3 = c(x3, y3, x1, y1, gx, gy)*c(x3, y3, x1, y1, xp, yp) > 0
  print 'YES' if r1 and r2 and r3 else 'NO'

Submission status: Accepted

Solution code:
while 1:
    try:
        x1, y1, x2, y2, x3, y3, xp, yp = map(float, raw_input().split())
    except EOFError:
        break
    Points = [(x1, y1), (x2, y2), (x3, y3)]
    for i in xrange(3):
        A = Points[i]
        B = Points[(i + 1) % 3]
        C = Points[(i + 2) % 3]
        if A[0] - B[0] == 0:
            mark1 = C[0] - A[0]
            mark2 = xp - A[0]
        else:
            a = (A[1] - B[1]) / (A[0] - B[0])
            b = A[1] - a * A[0]
            mark1 = C[1] - (a * C[0] + b)
            mark2 = yp - (a * xp + b)
        if not ((mark1 >= 0 and mark2 >= 0) or (mark1 <= 0 and mark2 <= 0)):
            print "NO"
            break
    else:
        print "YES"

Submission status: Accepted

Solution code:
import math

def L(x1,y1,x2,y2):
  return math.sqrt((x1-x2)**2+(y1-y2)**2)

def S(a,b,c):
  s=(a+b+c)/2
  return math.sqrt(s*(s-a)*(s-b)*(s-c))

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

Submission status: Accepted

Solution code:
import math

def L(x1, y1, x2, y2):
  return math.sqrt((x1 - x2)**2+(y1 - y2)**2)

def S(a, b, c):
  s=(a + b + c)/2
  return math.sqrt(s*(s - a)*(s - b)*(s - c))

while True:
  try:
    x1, y1, x2, y2, x3, y3, xp, yp = map(float, raw_input().split())
    a = L(x1, y1, x2, y2)
    b = L(x1, y1, x3, y3)
    c = L(x2, y2, x3, y3)
    p1 = L(x1, y1, xp, yp)
    p2 = L(x2, y2, xp, yp)
    p3 = L(x3, y3, xp, yp)

    if S(a, p2, p1)+S(b, p1, p3)+S(c, p3, p2)-S(a, b, c) > 0.0000001:
      print "NO"
    else:
      print "YES"
  except:
    break

Submission status: Accepted

Solution code:
# ２点(a, b) (c, d)を通る直線の傾きと切片を返す
def func(a, b, c, d):
    k = (d - b) / (c - a)
    h = d - k * c
    return k, h


# ２点と通る直線のf(x)を返す
def fx(a, b, c, d, x):
    k, h = func(a, b, c, d)
    return k * x + h


def main():
    import sys
    for dataset in sys.stdin:
        ans = 'NO'
        try :
            a, b, c, d, e, f, px, py = map(float, dataset.split())
        except:
            break
        T = [(a, b), (c, d), (e, f)]
        T.sort(key=lambda x: (x[0], x[1]))
        a, b, c, d, e, f = T[0][0], T[0][1], T[1][0], T[1][1], T[2][0], T[2][1]
        # 共通なxを持つ２点が存在するか判定し、する場合
        if a == c:
            if  a < px and fx(a, b, e, f, px) < py and fx(c, d, e, f, px) > py:
                ans = 'YES'
        elif c == e:
            if px < e and fx(a, b, c, d, px) < py and fx(a, b, e, f, px) > py:
                ans = 'YES'
        else:  # ３点において共通のxを持たない場合
            if fx(a, b, e, f, c) < d:  # 中間点が残り２点を通る直線より上にあるケース
                if fx(a, b, c, d, px) > py and fx(c, d, e, f, px) > py and fx(a, b, e, f, px) < py:
                    ans = 'YES'
            else:
                if fx(a, b, c, d, px) < py and fx(c, d, e, f, px) < py and fx(a, b, e, f, px) > py:
                    ans = 'YES'

        print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

def cross_product(a,b):#a,bは複素数、だけどベクトル扱いしよう
    return (a.conjugate()*b).imag

def abs_area_vector(ax,ay,bx,by):#3点(0,0)(ax,ay)(bx,by)で構成される三角形の面積の絶対値
    return abs(0.5 * (cross_product(complex(ax,ay),complex(bx,by))))

def abs_area_3point(ax,ay,bx,by,cx,cy):#3点(ax,ay)(bx,by)(cx,cy)で構成される三角形の面積の絶対値
    return abs_area_vector(bx-ax,by-ay,cx-ax,cy-ay)

try:
    while True:
        x1,y1,x2,y2,x3,y3,xp,yp = map(float,input().split())
        abc = abs_area_3point(x1,y1,x2,y2,x3,y3)
        pab = abs_area_3point(x1,y1,x2,y2,xp,yp)
        pbc = abs_area_3point(x2,y2,x3,y3,xp,yp)
        pca = abs_area_3point(x1,y1,x3,y3,xp,yp)
        #ここらへんで結構ミスあったから今度からはもっと簡潔に書けるように何か関数でも用意すべき
        print("NO" if pab * pbc * pca == 0 or abc != pab + pbc + pca else "YES")
except  (EOFError,ValueError):
    pass

Submission status: Accepted

Solution code:
try:
    while True:
        P= list(map(float,input().split()))
        a, b, c, q = [complex(P[i*2],P[i*2+1]) for i in range(4)]
        x,y,z= a-q,b-q,c-q
        xx= (x.conjugate()*y).imag
        yy= (y.conjugate()*z).imag
        zz= (z.conjugate()*x).imag
        if (xx>0 and yy>0 and zz>0) or (xx<0 and yy<0 and zz<0):
            print("YES")
        else:
            print("NO")
except EOFError: 
    pass

Submission status: Accepted

Solution code:
def cross_product(a,b):
  return (a.conjugate()*b).imag
try:
    while True:
        P = list(map(float,input().split()))
        a, b, c, p = [complex(P[i*2],P[i*2+1]) for i in range(4)]
        S = cross_product(p-a,p-b)
        T = cross_product(p-b,p-c)
        U = cross_product(p-c,p-a)
        if S*T > 0 and T*U >0:
            print('YES')
        else:
            print('NO')
except EOFError:
    pass

Submission status: Accepted

Solution code:
try:
    while True:
        x1, y1, x2, y2, x3, y3, xp, yp = map(float, input().split())
        a = complex(x1, y1)
        b = complex(x2, y2)
        c = complex(x3, y3)
        p = complex(xp, yp)
        s1 = ((a - p).conjugate() * (b - p)).imag
        s2 = ((b - p).conjugate() * (c - p)).imag
        s3 = ((c - p).conjugate() * (a - p)).imag
        if (s1 > 0) ^ (s2 > 0) == False and (s2 > 0) ^ (s3 > 0) == False:
            print('YES')
        else:
            print("NO")
except EOFError:
    exit()

Submission status: Accepted

Solution code:
import math
import cmath
def dot(a:complex,b:complex):
  return (a.conjugate()*b).real
def cross(a:complex,b:complex):
  return (a.conjugate()*b).imag
next=[1,2,0]
try:
  while True:
    l=list(map(float,input().split()))
    p=[complex(l[2*j],l[2*j+1]) for j in range(4)]
    flg_ans=True
    sgn=1 if cross(p[0]-p[3],p[1]-p[3])>0 else -1
    for i in range(3):
      flg_ans=flg_ans and (sgn*cross(p[i]-p[3],p[next[i]]-p[3]))>0
    print('YES' if flg_ans else 'NO')
except EOFError:
  pass

Submission status: Accepted

Solution code:
def stl1(x):
    if a == e:
        y = b
    else:
        y = (f-b)*(x-a)/(e-a) +b

    return(y)

def stl2(x):
    if c == e:
        y = f
    else:
        y = (d-f)*(x-e)/(c-e) +f

    return(y)

def stl3(x):
    if c == a:
        y = b
    else:
        y = (d-b)*(x-a)/(c-a) +b
        
    return(y)

while True:
    try:
        lst = list(map(float, input().split()))
        point1 = [lst[0], lst[1]]
        point2 = [lst[2], lst[3]]
        point3 = [lst[4], lst[5]]
        xp, yp = lst[6], lst[7]

        pointlst = [point1, point2, point3]
        pointlst.sort()
        a, b, e, f, c, d = pointlst[0][0], pointlst[0][1], pointlst[1][0], pointlst[1][1], pointlst[2][0], pointlst[2][1]

        if a <= xp and xp <= e:
            bdr1 = stl1(xp)
            bdr3 = stl3(xp)

            if min(bdr1, bdr3) <= yp and yp <= max(bdr1, bdr3):
                print("YES")

            else:
                print("NO")
        
        elif e < xp and xp <= c:
            bdr2 = stl2(xp)
            bdr3 = stl3(xp)

            if min(bdr2, bdr3) <= yp and yp <= max(bdr2, bdr3):
                print("YES")
            
            else:
                print("NO")

        else:
            print("NO")

    except EOFError:
        break

Submission status: Accepted

Solution code:
def cross3(a, b, c):
    return (b[0] - a[0])*(c[1] - a[1]) - (b[1] - a[1])*(c[0] - a[0])
for line in open(0).readlines():
    x1, y1, x2, y2, x3, y3, xp, yp = map(float, line.split())
    p1 = (x1, y1); p2 = (x2, y2); p3 = (x3, y3); pp = (xp, yp)
    if cross3(p1, p2, p3) < 0:
        p1, p2 = p2, p1
    if cross3(p1, p2, pp) > 0 and cross3(p1, pp, p3) > 0 and cross3(p2, p3, pp) > 0:
        print("YES")
    else:
        print("NO")

Submission status: Accepted

Solution code:
while True:
    try:
        x1, y1, x2, y2, x3, y3, xp, yp = list(map(float, input().split()))

        sign = lambda x1, y1, x2, y2, x3, y3: (x1 - x3) * (y2 - y3) - (x2 - x3) * (y1 - y3)
        b1 = sign(xp, yp, x1, y1, x2, y2) < 0.0
        b2 = sign(xp, yp, x2, y2, x3, y3) < 0.0
        b3 = sign(xp, yp, x3, y3, x1, y1) < 0.0


        if b1 == b2 and b2 == b3:
            print("YES")
        else:
            print("NO")
    except:
        break

Submission status: Accepted

Solution code:
import sys
  
for s in sys.stdin:
    x1,y1,x2,y2,x3,y3,xp,yp = [ float(x) for x in s.split() ]

    v12 = (x2-x1, y2-y1)
    v23 = (x3-x2, y3-y2)
    v31 = (x1-x3, y1-y3)
    v1p = (xp-x1, yp-y1)
    v2p = (xp-x2, yp-y2)
    v3p = (xp-x3, yp-y3)
    cp1 = v12[0]*v1p[1] - v1p[0]*v12[1]
    cp2 = v23[0]*v2p[1] - v2p[0]*v23[1]
    cp3 = v31[0]*v3p[1] - v3p[0]*v31[1]

    if cp1 > 0 and cp2 > 0 and cp3 > 0:
        print('YES')
    elif cp1 < 0 and cp2 < 0 and cp3 < 0:
        print('YES')
    else:
        print('NO')

Submission status: Accepted

Solution code:
while True :
    try :
        x1, y1, x2, y2, x3, y3, xp, yp = map(float, input().split())
        
        # 三角形の回転方向で判定する
        # 三角形PAB, PBC, PCAの回転が全て同じならば、
        # 点Pは三角形ABC内に存在する
        # 三角形ABCの回転の方向は、
        # x1(y2 - y3) + x2(y3 - y1) + x3(y1 - y2)
        # の符号で判断できる
        # 正なら左周り、負なら右回り
        
        a = xp * (y1 - y2) + x1 * (y2 - yp) + x2 * (yp - y1)
        b = xp * (y2 - y3) + x2 * (y3 - yp) + x3 * (yp - y2)
        c = xp * (y3 - y1) + x3 * (y1 - yp) + x1 * (yp - y3)
            
        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 r(a, b, c, d, e, f):
    return a * (d-f) + c * (f-b) + e * (b-d) > 0
  
while True:
    try: line = list(map(float, input().split()))
    except: break
      
    x1, y1, x2, y2, x3, y3, xp, yp = line
    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:
import sys
def f(a,b,c,d):z=(c-a)*(y-d)-(d-b)*(x-c);return[-1*(z==0),1][z>0]
for e in sys.stdin:
 p,q,r,s,t,u,x,y=map(float,e.split())
 print(['NO','YES'][f(p,q,r,s)==f(r,s,t,u)==f(t,u,p,q)])

Submission status: Accepted

Solution code:
def r(a, b, c, d, e, f):
    return a * (d-f) + c * (f-b) + e * (b-d) > 0
 
while True:
    try: line = list(map(float, input().split()))
    except: break
     
    x1, y1, x2, y2, x3, y3, xp, yp = line
    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:
import sys
def gaiseki(x0, y0, x1, y1):
    return x0*y1 - y0*x1
def muki(x0, y0, x1, y1, x2, y2):
    return gaiseki(x1-x0, y1-y0, x2-x1, y2-y1) > 0
for line in sys.stdin:
    x0, y0, x1, y1, x2, y2, xp, yp = map(float, line.split())
    m0 = muki(xp, yp, x0, y0, x1, y1)
    m1 = muki(xp, yp, x1, y1, x2, y2)
    m2 = muki(xp, yp, x2, y2, x0, y0)
    if m0 == m1 and m1 == m2:
        print('YES')
    else:
        print('NO')

Submission status: Accepted

Solution code:
def isPos(p,x,y):
    return ((x-p).conjugate()*(y-p)).imag>0

try:
    while True:
        X=list(map(float,input().split()))
        a,b,c,p=map(lambda x:complex(*x),[X[:2],X[2:4],X[4:6],X[6:]])
        print(['NO','YES'][isPos(p,a,b)==isPos(p,b,c)==isPos(p,c,a)])
except EOFError: pass

Submission status: Accepted

Solution code:
while True:
  try:
    x1, y1, x2, y2, x3, y3, xp, yp = map(float, input().split())
  except EOFError:
    break
  vec_b = [x2-x1, y2-y1]
  vec_c = [x3-x1, y3-y1]
  vec_p = [xp-x1, yp-y1]
  a = (vec_p[0]*vec_c[1] - vec_p[1]*vec_c[0]) / (vec_b[0]*vec_c[1] - vec_b[1]*vec_c[0])
  b = (vec_p[0]*vec_b[1] - vec_p[1]*vec_b[0]) / (vec_b[1]*vec_c[0] - vec_b[0]*vec_c[1])
  if ((a > 0) and (b > 0) and (a+b < 1)):
    print("YES")
  else:
    print("NO")

Submission status: Accepted

Solution code:
while 1:
    try:
        x1,y1,x2,y2,x3,y3,xp,yp=map(float,input().split())
        a=((x1-x2)**2+(y1-y2)**2)**0.5
        b=((x2-x3)**2+(y2-y3)**2)**0.5
        c=((x3-x1)**2+(y3-y1)**2)**0.5
        s=(a+b+c)/2
        S=(s*(s-a)*(s-b)*(s-c))**0.5
        d=((x1-xp)**2+(y1-yp)**2)**0.5
        e=((x2-xp)**2+(y2-yp)**2)**0.5
        f=((x3-xp)**2+(y3-yp)**2)**0.5
        sa=(a+d+e)/2
        sb=(b+e+f)/2
        sc=(c+f+d)/2
        Sa=(sa*(sa-a)*(sa-d)*(sa-e))**0.5
        Sb=(sb*(sb-b)*(sb-e)*(sb-f))**0.5
        Sc=(sc*(sc-c)*(sc-f)*(sc-d))**0.5
        Sp=Sa+Sb+Sc
        if abs(S-Sp)<=0.001**2:
            print("YES")
        else:
            print("NO")
    except:break

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    while True:
        try:
            x1, y1, x2, y2, x3, y3, xp, yp = map(float, input().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")
        except EOFError:
            break

Submission status: Accepted

Solution code:
def cross(a,b):
    return (a.conjugate()*b).imag
def is_in_triangle(X1,Y1,X2,Y2,X3,Y3,Xp,Yp):
    z1 = complex(X1-Xp,Y1-Yp)
    z2 = complex(X2-Xp,Y2-Yp)
    z3 = complex(X3-Xp,Y3-Yp)
    if cross(z1,z2) * cross(z2,z3) > 0:
        if cross(z2,z3) * cross(z3,z1) > 0:
            return True
    else:
        return False
lst = []
try:
    while True:
        P = tuple(map(float,input().strip().split()))
        lst.append(P)
except EOFError:
    pass
N = len(lst)
for i in range(N):
    if is_in_triangle(*lst[i]):
        print("YES")
    else:
        print("NO")

Submission status: Accepted

Solution code:
E = 10**-10

def cp(a, b):
    c = [a[1]*b[2] - a[2]*b[1],
        a[2]*b[0] - a[0]*b[2],
        a[0]*b[1] - a[1]*b[0]]
    return c

while True:
    try:
        x1,y1,x2,y2,x3,y3,xp,yp = [float(i) for i in input().split()]
        ax = x3-x1
        ay = y3-y1
        bx = x1-x2
        by = y1-y2
        cx = x2-x3
        cy = y2-y3
        pax = xp-x1
        pay = yp-y1
        pbx = xp-x2
        pby = yp-y2
        pcx = xp-x3
        pcy = yp-y3
        ca = [bx,by,0]
        ab = [cx,cy,0]
        bc = [ax,ay,0]
        pa = [pax,pay,0]
        pb = [pbx,pby,0]
        pc = [pcx,pcy,0]
        cp1 = cp(ca,pa)[2]
        cp2 = cp(ab,pb)[2]
        cp3 = cp(bc,pc)[2]
        if abs(cp1 - abs(cp1)) < E:
            sig1 = 1
        elif abs(cp1 + abs(cp1)) < E:
            sig1 = -1
        if abs(cp2 - abs(cp2)) < E:
            sig2 = 1
        elif abs(cp2 + abs(cp2)) < E:
            sig2 = -1
        if abs(cp3 - abs(cp3)) < E:
            sig3 = 1
        elif abs(cp3 + abs(cp3)) < E:
            sig3 = -1
        if abs(sig1 + sig2 + sig3) == 3:
            print('YES')
        else:
            print('NO')
    except EOFError:
        break

Submission status: Accepted

Solution code:
def r(a, b, c, d, e, f):
    return a * (d-f) + c * (f-b) + e * (b-d) > 0

while True:
    try: line = list(map(float, input().split()))
    except: break
    
    x1, y1, x2, y2, x3, y3, xp, yp = line
    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:
while(True):
    try:
        x1,y1,x2,y2,x3,y3,xp,yp = map(float, input().split())
        c1 = (x2-x1)*(yp-y1)-(y2-y1)*(xp-x1)
        c2 = (x3-x2)*(yp-y2)-(y3-y2)*(xp-x2)
        c3 = (x1-x3)*(yp-y3)-(y1-y3)*(xp-x3)
        if (c1<0 and c2<0 and c3<0) or (c1>0 and c2>0 and c3>0):
            print("YES")
            continue
        print("NO")
    except:
        break

Submission status: Accepted

Solution code:
from collections import namedtuple

Point = namedtuple('Point', ('x', 'y'))

def sign (p1, p2, p3):
  return (p1.x - p3.x) * (p2.y - p3.y) - (p2.x - p3.x) * (p1.y - p3.y);

while True:
  try:
    x = list(map(float, input().split()))
    p1 = Point(x[0], x[1])
    p2 = Point(x[2], x[3])
    p3 = Point(x[4], x[5])
    pp = Point(x[6], x[7])
    b1 = sign(pp, p1, p2) < 0.0
    b2 = sign(pp, p2, p3) < 0.0
    b3 = sign(pp, p3, p1) < 0.0
    if (b1 == b2) and(b2 == b3):
      print('YES')
    else:
      print('NO')
  except:
    break

Submission status: Accepted

Solution code:
def rot(xa,ya,xb,yb,xc,yc):
    r=(xb-xa)*(yc-ya)-(xc-xa)*(yb-ya)
    if r>0:return 1
    if r==0:return 0
    if r<0:return -1
while 1:
    try:
        x1,y1,x2,y2,x3,y3,xp,yp=map(float,input().split(" "))
        if rot(x1,y1,x2,y2,xp,yp)==rot(x2,y2,x3,y3,xp,yp)==rot(x3,y3,x1,y1,xp,yp):
            print("YES")
        else:
            print("NO")
    except:break

Submission status: Accepted

Solution code:
def point(a,b):
    return a[0]*b[0]+a[1]*b[1]
def euclid(a):
    return (a[0]**2+a[1]**2)**(1/2)
def cos(a,b):
    return point(a,b)/(euclid(a)*euclid(b))
while 1:
    try:
        ax,ay,bx,by,cx,cy,px,py = map(float, input().split(" "))
        ab = [bx-ax, by-ay]
        ac = [cx-ax, cy-ay]
        ba = [ax-bx, ay-by]
        bc = [cx-bx, cy-by]
        ap = [px-ax, py-ay]
        bp = [px-bx, py-by]
        if min(cos(ab,ap),cos(ac,ap)) > cos(ab,ac) and min(cos(ba,bp),cos(bc,bp)) > cos(ba,bc):
            print("YES")
        else:
            print("NO")
    except:
        break

Submission status: Accepted

Solution code:
# A Point in a Triangle
import math
def simul_eq(a,b,c,d,e,f):
    # A = [[a,b],[d,e]]
    C = [c,f]
    detA = a*e - b*d
    # if detA == 0: raise # det(A) == 0.
    At = [[e,-b],[-d,a]]
    x = sum(map((lambda x,y: x*y), At[0], C)) / detA
    y = sum(map((lambda x,y: x*y), At[1], C)) / detA
    return (x,y)
ss = input().split()
while 1:
    x1,y1,x2,y2,x3,y3,xp,yp = map(float,ss)
    s,t = simul_eq(x2-x1, x3-x1, xp-x1, y2-y1, y3-y1, yp-y1)
    if 0 < s < 1 and 0 < t < 1 and 0 < s + t < 1:
        print('YES')
    else:
        print('NO')
    try: ss = input().split()
    except EOFError: break

Submission status: Runtime Error

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

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
while True:
    line = input()
    if line == "":
        break
    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: Runtime Error

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, raw_input().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: Runtime Error

Solution code:
# coding: utf-8
# Here your code !
# coding: utf-8
import numpy as np

l = map(float, raw_input().split())
x1 = l[2]-l[0]
x2 = l[3]-l[1]

y1 = l[4]-l[0]
y2 = l[5]-l[1]

p1 = l[6]-l[0]
p2 = l[7]-l[1]

matrix_A = np.array([[x1,y1],[x2,y2]])
vector_p = np.array([p1,p2])

x = np.linalg.solve(matrix_A, vector_p)

if 0<abs(x[0])+abs(x[1])<1:
    print "Yes"
else:
    print "No"

Submission status: Runtime Error

Solution code:
i = 1
while True:
    
    l = map(float, raw_input().split())
    x1 = l[2]-l[0]
    x2 = l[3]-l[1]
    
    y1 = l[4]-l[0]
    y2 = l[5]-l[1]
    
    p1 = l[6]-l[0]
    p2 = l[7]-l[1]
    
    matrix_A = np.array([[x1,y1],[x2,y2]])
    vector_p = np.array([p1,p2])
    
    x = np.linalg.solve(matrix_A, vector_p)
    
    if 0<abs(x[0])+abs(x[1])<1:
       print "Yes"
    else:
        print "No"
    
    if i > 100:
        break
    i += 1