Problem:


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

凸？

平面上の異なる 4 点　$A (x_a, y_a)$, $B (x_b, y_b)$, $C (x_c, y_c)$, $D(x_d, y_d)$ の座標を読み込んで、それら 4 点を頂点とした四角形 $ABCD$ に凹みがなければ YES、凹みがあれば NO と出力するプログラムを作成してください。

凹みのある四角形とは図 1 のような四角形です。

Input

複数のデータセットが与えられます。各データセットの形式は以下のとおりです。

$x_a$,$y_a$,$x_b$,$y_b$,$x_c$,$y_c$,$x_d$,$y_d$

$x_a$, $y_a$, $x_b$, $y_b$, $x_c$, $y_c$, $x_d$, $y_d$ はそれぞれ -100 以上 100 以下であり、実数で与えられます。

1 直線上に 3 つ以上点が並ぶことはないものとします。また、入力順に点を結んでいけば、四角形になる順番に点の座標が入力されるものとします。（つまり、図 2 のような形になる順番で点が与えられることはありません。)

データセットの数は 100 を超えません。

Output

各データセットごとに、YES または NO を１行に出力します。

Sample Input

0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0
0.0,0.0,3.0,0.0,1.0,1.0,1.0,3.0

Output for the Sample Input

YES
NO



Sample input:
0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0
0.0,0.0,3.0,0.0,1.0,1.0,1.0,3.0


Sample output:
YES
NO

Submission status: Accepted

Solution code:
while True:
    try:
        x_a, y_a, x_b, y_b, x_c, y_c, x_d, y_d = map(float, input().split(","))
        ab = [x_b - x_a, y_b - y_a]
        bc = [x_c - x_b, y_c - y_b]
        cd = [x_d - x_c, y_d - y_c]
        da = [x_a - x_d, y_a - y_d]
        crs_a = -(ab[0]*da[1] - ab[1]*da[0])
        crs_b = -(bc[0]*ab[1] - bc[1]*ab[0])
        crs_c = -(cd[0]*bc[1] - cd[1]*bc[0])
        crs_d = -(da[0]*cd[1] - da[1]*cd[0])
        if crs_a*crs_b*crs_c*crs_d < 0:
            print("NO")
        else:
            print("YES")
    except:
        break

Submission status: Accepted

Solution code:
import sys
for e in sys.stdin:
 e=list(map(float,e.split(',')));n=0
 for i in range(0,8,2):
  if(e[i]-e[(2+i)%8])*(e[(5+i)%8]-e[(3+i)%8])-(e[1+i]-e[(3+i)%8])*(e[(4+i)%8]-e[(2+i)%8])>0:n+=1
 print(['YES','NO'][n%4>0])

Submission status: Accepted

Solution code:
import sys
for e in sys.stdin:
 e=list(map(float,e.split(',')))
 print(['YES','NO'][sum((e[i]-e[(2+i)%8])*(e[(5+i)%8]-e[(3+i)%8])-(e[1+i]-e[(3+i)%8])*(e[(4+i)%8]-e[(2+i)%8])>0 for i in range(0,8,2))%4>0])

Submission status: Accepted

Solution code:
def judge(p1,p2,p3,p4):
    t1 = (p3[0] - p4[0]) * (p1[1] - p3[1]) + (p3[1] - p4[1]) * (p3[0] - p1[0])
    t2 = (p3[0] - p4[0]) * (p2[1] - p3[1]) + (p3[1] - p4[1]) * (p3[0] - p2[0])
    t3 = (p1[0] - p2[0]) * (p3[1] - p1[1]) + (p1[1] - p2[1]) * (p1[0] - p3[0])
    t4 = (p1[0] - p2[0]) * (p4[1] - p1[1]) + (p1[1] - p2[1]) * (p1[0] - p4[0])
    return t1*t2>0 and t3*t4>0 
while True:
	try:
		x1,y1,x2,y2,x3,y3,x4,y4=map(float, input().split(","))
		A=[x1,y1]
		B=[x2,y2]
		C=[x3,y3]
		D=[x4,y4]
		if judge(A,B,C,D)==False :
			print("NO")
		else:
			print("YES")
	except EOFError:
		break

Submission status: Accepted

Solution code:
import math

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

def Cp(p1, p2, p3):
    xa = p1.x-p2.x
    ya = p1.y-p2.y
    xb = p3.x-p2.x
    yb = p3.y-p2.y
    return xa*yb-ya*xb

def get_input():
    while True:
        try:
            yield ''.join(input())
        except EOFError:
            break

N = list(get_input())
for l in range(len(N)):

    x1,y1,x2,y2,x3,y3,x4,y4 = [float(i) for i in N[l].split(",")]

    p1 = Point(x1,y1)
    p2 = Point(x2,y2)
    p3 = Point(x3,y3)
    p4 = Point(x4,y4)

    cp1 = Cp(p1,p2,p3)
    cp2 = Cp(p2,p3,p4)
    cp3 = Cp(p3,p4,p1)
    cp4 = Cp(p4,p1,p2)

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

Submission status: Accepted

Solution code:
from decimal import Decimal
import sys
for l in sys.stdin:
  xa,ya,xb,yb,xc,yc,xd,yd=list(map(Decimal,l.split(",")))
  a=xd-xb
  b=yd-yb
  c=xa-xb
  d=ya-yb
  e=xc-xb
  f=yc-yb
  try:
    s=(a*f-b*e)/(c*f-d*e)
    t=(-a*d+b*c)/(c*f-d*e)
  except:
    print("NO")
  if s>=0 and t>=0 and s+t>=1:
    print("YES")
  else:
    print("NO")

Submission status: Accepted

Solution code:
# AOJ 00035: Is it Convex?
# Python3 2018.6.17 bal4u

EPS = 0.0001

# a, b, はラインの同一側にあるか。　-1, 0, 1
def atSameSide(a, b, line):
	sa = (line[1].real-line[0].real)*(a.imag-line[0].imag) \
		 + (line[1].imag-line[0].imag)*(line[0].real-a.real);
	sb = (line[1].real-line[0].real)*(b.imag-line[0].imag) \
		 + (line[1].imag-line[0].imag)*(line[0].real-b.real);
	if -EPS <= sa and sa <= EPS: return 0 		 # a in line
	if -EPS <= sb and sb <= EPS: return 0 		 # b in line
	if sa*sb >= 0: return 1           # a,b at same side
	return -1;

while True:
	try: p = list(map(float, input().split(',')))
	except: break
	
	p1 = complex(p[0], p[1])
	p2 = complex(p[2], p[3])
	p3 = complex(p[4], p[5])
	p4 = complex(p[6], p[7])
	if atSameSide(p2, p4, [p1, p3]) == -1 and \
	   atSameSide(p1, p3, [p2, p4]) == -1: print('YES')
	else: print('NO')

Submission status: Accepted

Solution code:
import sys

def cross(p0, p1, p2):
  dx1, dx2 = p1[0] - p0[0], p2[0] - p0[0]
  dy1, dy2 = p1[1] - p0[1], p2[1] - p0[1]
  return dy2 * dx1 - dy1 * dx2
 
for line in iter(sys.stdin.readline, ''):
  l = [float(r) for r in line.split(',')]
  a, b, c, d = l[0:2], l[2:4], l[4:6], l[6:8]
  print 'YES' if (cross(a, c, b) * cross(a, c, d)) < 0 and (cross(b, d, a) * cross(b, d, c) < 0) else 'NO'

Submission status: Accepted

Solution code:
import sys
def cross(x1,y1,x2,y2):
    return x1*y2-y1*x2
for line in sys.stdin.readlines():
    line=map(float,line.strip().split(","))
    x,y=line[0::2],line[1::2]
    xv=[x[(i+1)%4]-x[i] for i in xrange(4)]
    yv=[y[(i+1)%4]-y[i] for i in xrange(4)]
    if 0<len([i for i in xrange(4) if cross(xv[i],yv[i],xv[(i+1)%4],yv[(i+1)%4])>0])<4: print "NO"
    else:print "YES"
#temp

Submission status: Accepted

Solution code:
class Point(object):
    x = 0.0
    y = 0.0
    def __init__(self, x, y):
        self.x = x
        self.y = y
    def __sub__(left, right):
        return Point(left.x - right.x, left.y - right.y)
    #cross
    def __mul__(left, right):
        return left.x * right.y - left.y * right.x
def f(n):
    return n<0
while True:
    try:
        (xa,ya,xb,yb,xc,yc,xd,yd) = [float(i) for i in raw_input().split(',')]
        a = Point(xa,ya)
        b = Point(xb,yb)
        c = Point(xc,yc)
        d = Point(xd,yd)
        ab = a - b
        bc = b - c
        cd = c - d
        da = d - a
        if((f(ab*bc) + f(bc*cd)) + (f(cd*da) + f(da*ab)) in (0,4)):
            print 'YES'
        else:
            print 'NO'
    except:
        break

Submission status: Accepted

Solution code:
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin
from collections import namedtuple
Point = namedtuple('Point', 'x y')

def make_test(p1, p2):
    if p1.x == p2.x:
        gradient = p1.x
        return lambda p: gradient > p.x
    gradient = (p1.y - p2.y) / (p1.x - p2.x)
    y_intercept = p1.y - gradient * p1.x
    return lambda p: gradient * p.x + y_intercept > p.y

for line in stdin:
    it = (float(s) for s in line.split(','))
    A, B, C, D = (Point(next(it), next(it)) for _ in xrange(4))

    f = make_test(A, C)
    g = make_test(B, D)
    if f(B) == f(D) or g(A) == g(C):
        print('NO')
    else:
        print('YES')

Submission status: Accepted

Solution code:
while True:
	try:
		s = [] ; right = 0 ; left = 0
		x = map(float,raw_input().split(','))
		for val in xrange(4):
			if x[0]-x[2] != 0:
				if (x[0]-x[2])*(x[5]-x[1]) > (x[1]-x[3])*(x[4]-x[0]): left += 1
				else: right += 1
			else:
				if x[1] < x[3]:
					if x[0] < x[4]: left += 1
					else: right += 1
				else:
					if x[0] > x[4]: left += 1
					else: right += 1
			a=x[0] ; x[0]=x[2] ; x[2]=x[4] ; x[4]=x[6] ; x[6]=a
			b=x[1] ; x[1]=x[3] ; x[3]=x[5] ; x[5]=x[7] ; x[7]=b
		if right == 4 or left == 4: print 'YES'
		else: print 'NO'
	except: break

Submission status: Accepted

Solution code:
# coding: utf-8

#import time
#import sys
#import numpy as np
def sign(x):
    if x>0: return 1
    elif x==0: return 0
    else: return -1

def f0035(p1,p2,p3):
    x1, y1 = p1
    x2, y2 = p2
    x3, y3 = p3
    return sign((y3-y1)*(x2-x1)-(y2-y1)*(x3-x1))

while True:
    try:
        dt =map(float, raw_input().split(","))
    except:
        break

    p1=dt[0:2]
    p2=dt[2:4]
    p3=dt[4:6]
    p4=dt[6:8]
    if f0035(p1,p3,p2) != f0035(p1,p3,p4) and f0035(p2,p4,p1) != f0035(p2,p4,p3): print "YES"
    else: print "NO"

Submission status: Accepted

Solution code:
def sign(x):
    if x>0: return 1
    elif x==0: return 0
    else: return -1

def f0035(p1,p2,p3):
    x1, y1 = p1
    x2, y2 = p2
    x3, y3 = p3
    return sign((y3-y1)*(x2-x1)-(y2-y1)*(x3-x1))

while True:
    try:
        dt =map(float, raw_input().split(","))
    except:
        break

    p1=dt[0:2]
    p2=dt[2:4]
    p3=dt[4:6]
    p4=dt[6:8]
    if f0035(p1,p3,p2) != f0035(p1,p3,p4) and f0035(p2,p4,p1) != f0035(p2,p4,p3): print "YES"
    else: print "NO"

Submission status: Accepted

Solution code:
import sys
def sign(x):
    if x>0: s=1
    elif x==0: s=0
    else: s=-1
    return s

def f(p1,p2,p3):
    s = sign((p3[1]-p1[1])*(p2[0]-p1[0])-(p2[1]-p1[1])*(p3[0]-p1[0]))
    return s

for s in sys.stdin:
    D =map(float, s.split(","))
    p1=D[0:2]; p2=D[2:4]; p3=D[4:6]; p4=D[6:8]
    x = f(p1,p3,p2) != f(p1,p3,p4) and f(p2,p4,p1) != f(p2,p4,p3)
    print ["NO","YES"][x]

Submission status: Accepted

Solution code:
import sys
def sign(x):
    if x>0: s=1
    elif x<0: s=-1
    else: s=0
    return s

def f(p1,p2,p3):
    x1,y1 = p1
    s = sign((p3[1]-y1)*(p2[0]-x1)-(p2[1]-y1)*(p3[0]-x1))
    return s

for s in sys.stdin:
    D = map(float, s.split(","))
    p1 = D[0:2]
    p2 = D[2:4]
    p3 = D[4:6]
    p4 = D[6:8]
    x = f(p1,p3,p2) != f(p1,p3,p4) and f(p2,p4,p1) != f(p2,p4,p3)
    print ["NO","YES"][x]

Submission status: Accepted

Solution code:
import sys
def sign(x):
    if x>0: s=1
    elif x<0: s=-1
    else: s=0
    return s

def f(p1,p2,p3):
    x1,y1 = p1
    s = sign((p3[1]-y1)*(p2[0]-x1)-(p2[1]-y1)*(p3[0]-x1))
    return s

for s in sys.stdin:
    D = map(float, s.split(","))
    p1 = D[0:2]; p2 = D[2:4]; p3 = D[4:6]; p4 = D[6:8]
    x = f(p1,p3,p2) != f(p1,p3,p4) and f(p2,p4,p1) != f(p2,p4,p3)
    print ["NO","YES"][x]

Submission status: Accepted

Solution code:
def f(x,y,x1,y1,x2,y2):
    return (x2-x1)*y-(y2-y1)*x+x1*y2-x2*y1

while True:
    try:
        ax,ay,bx,by,cx,cy,dx,dy = map(float, raw_input().split(","))
        if f(ax,ay,bx,by,dx,dy)*f(cx,cy,bx,by,dx,dy) < 0 and f(dx,dy,ax,ay,cx,cy)*f(bx,by,ax,ay,cx,cy) < 0:
            print "YES"
        else: print "NO"
    except:
        break

Submission status: Accepted

Solution code:
while True:
    try:
        lst = list(map(float, input().split(',')))
        xa, ya = lst[0], lst[1]
        xb, yb = lst[2], lst[3]
        xc, yc = lst[4], lst[5]
        xd, yd = lst[6], lst[7]

        ans1 = ((yc - ya)*xb - (xc - xa)*yb + (xc * ya - xa * yc))
        ans2 = ((yc - ya)*xd - (xc - xa)*yd + (xc * ya - xa * yc))
        ans3 = ((yb - yd)*xa - (xb - xd)*ya + (xb * yd - xd * yb))
        ans4 = ((yb - yd)*xc - (xb - xd)*yc + (xb * yd - xd * yb))

        if ans1*ans2 > 0 or ans3*ans4 > 0:
            print("NO")

        else:
            print("YES")

    except EOFError:
        break

Submission status: Accepted

Solution code:
import sys
readlines = sys.stdin.readlines
write = sys.stdout.write
def cross3(a, b, c):
    return (b[0]-a[0])*(c[1]-a[1]) - (b[1]-a[1])*(c[0]-a[0])
def solve():
    for line in readlines():
        xa, ya, xb, yb, xc, yc, xd, yd = map(float, line.split(","))
        P = [(xa, ya), (xb, yb), (xc, yc), (xd, yd)]
        D = []
        for i in range(4):
            p0 = P[i-2]; p1 = P[i-1]; p2 = P[i]
            D.append(cross3(p0, p1, p2))
        if all(e > 0 for e in D) or all(e < 0 for e in D):
            write("YES\n")
        else:
            write("NO\n")
solve()

Submission status: Accepted

Solution code:
while True:
  try:
    data = list(map(float,input().split(",")))
  except EOFError:
    break
  vec1 = [data[2]-data[0],data[3]-data[1]]
  vec2 = [data[4]-data[0],data[5]-data[1]]
  vec3 = [data[6]-data[0],data[7]-data[1]]
  a = (vec2[0]*vec3[1] - vec2[1]*vec3[0]) / (vec1[0]*vec3[1] - vec1[1]*vec3[0])
  b = (vec2[0]*vec1[1] - vec2[1]*vec1[0]) / (vec1[1]*vec3[0] - vec1[0]*vec3[1])
  if (a < 0 or b < 0) or a+b < 1.0:
    print("NO")
  else:
    print("YES")

Submission status: Accepted

Solution code:
#凸包を求める

def quickhull(l,r,s,k):
    if not s:
        return
    su = []
    sd = []
    a = (r[0]-l[0],r[1]-l[1])
    for x,y in s:
        b = (x-l[0],y-l[1])
        cro = cross(a,b)
        if cro > 0:
            su.append((x,y)) #上半分
        elif cro < 0:
            sd.append((x,y)) #下半分

    if su:
        c,d = direction(l,r,su[0])
        p = su[0]
        for i in range(1,len(su)):
            c_,d_ = direction(l,r,su[i])
            if c*d_ < c_*d:
                c,d = c_,d_
                p = su[i]
        k.append(tuple(p)) #もっとも離れた点を凸包の頂点に追加
        b = (l[0]-p[0],l[1]-p[1])
        c = (p[0]-r[0],p[1]-r[1])
        s1 = []
        s2 = []
        for x,y in su:
            b_ = (x-p[0],y-p[1])
            c_ = (x-r[0],y-r[1])
            cro_b,cro_c = cross(b,b_),cross(c,c_)
            if cro_b >= 0 and cro_c >= 0: #三角形内部判定
                continue
            else:
                if cro_b < 0:
                    s1.append((x,y))
                elif cro_c < 0:
                    s2.append((x,y))
        quickhull(l,p,s1,k) #再帰
        quickhull(p,r,s2,k)

    if sd:
        c,d = direction(l,r,sd[0])
        p = sd[0]
        for i in range(1,len(sd)):
            c_,d_ = direction(l,r,sd[i])
            if c*d_ < c_*d:
                c,d = c_,d_
                p = sd[i]
        k.append(tuple(p)) #もっとも離れた点を凸包の頂点に追加
        b = (l[0]-p[0],l[1]-p[1])
        c = (p[0]-r[0],p[1]-r[1])
        s1 = []
        s2 = []
        for x,y in sd:
            b_ = (x-p[0],y-p[1])
            c_ = (x-r[0],y-r[1])
            cro_b,cro_c = cross(b,b_),cross(c,c_)
            if cro_b <= 0 and cro_c <= 0: #三角形内部判定(ベクトルの向きにより上下で判定が異なることに注意)
                continue
            else:
                if cro_b > 0:
                    s1.append((x,y))
                elif cro_c > 0:
                    s2.append((x,y))
        quickhull(l,p,s1,k) #再帰
        quickhull(p,r,s2,k)
    return k

def cross(a,b): #外積
    return a[0]*b[1]-a[1]*b[0]

def direction(l,r,p): #点と直線の距離
    a = r[1]-l[1]
    b = l[0]-r[0]
    return (a*(p[0]-l[0])+b*(p[1]-l[1]))**2, a**2+b**2 #分子の2乗,分母の2乗
while 1:
    try:
        t = [float(x) for x in input().split(",")]
        s = []
        for i in range(len(t)//2):
            s.append((t[2*i],t[2*i+1]))
        s.sort()
        l = tuple(s.pop(0))
        r = tuple(s.pop(-1))
        k = quickhull(l,r,s,[l,r])
        if len(k) < 4:
            print("NO")
        else:
            print("YES")
    except:
        quit()

Submission status: Accepted

Solution code:
from math import atan, pi
E = 10**-10

def cross(a0,a1,b0,b1):
    return a0*b1-a1*b0

while(1):
    a = [0 for i in range(2)]
    b = [0 for i in range(2)]
    c = [0 for i in range(2)]
    d = [0 for i in range(2)]
    try:
        a[0],a[1],b[0],b[1],c[0],c[1],d[0],d[1] = [float(i) for i in input().split(",")]
        A = cross((d[1]-a[1]),(d[0]-a[0]),(b[1]-a[1]),(b[0]-a[0]))
        B = cross((c[1]-d[1]),(c[0]-d[0]),(a[1]-d[1]),(a[0]-d[0]))
        C = cross((b[1]-c[1]),(b[0]-c[0]),(d[1]-c[1]),(d[0]-c[0]))
        D = cross((a[1]-b[1]),(a[0]-b[0]),(c[1]-b[1]),(c[0]-b[0]))
        if A*B*C*D < 0:
            print("NO")
        else:
            print("YES")
    except EOFError:
        break

Submission status: Accepted

Solution code:
import sys

def menseki(x0,y0,x1,y1,x2,y2):
    return 0.5*abs((x1-x0)*(y2-y0)-(x2-x0)*(y1-y0))

def square_menseki(x0,y0,x1,y1,x2,y2,x3,y3):
    return 0.5*abs((x0*y1-y0*x1)+(x1*y2-y1*x2)+(x2*y3-y2*x3)+(x3*y0-y3*x0))

for row in sys.stdin:
    x0,y0,x1,y1,x2,y2,x3,y3 = list(map(float, row.strip().split(',')))
    s = square_menseki(x0,y0,x1,y1,x2,y2,x3,y3)
    if s > menseki(x0,y0,x1,y1,x2,y2) and s > menseki(x0,y0,x1,y1,x3,y3) and s> menseki(x0,y0,x2,y2,x3,y3) and s > menseki(x1,y1,x2,y2,x3,y3):
        print('YES')
    else:
        print('NO')

Submission status: Accepted

Solution code:
while True:
    try: ipt = input()
    except: break

    c = list(map(float, ipt.split(',')))
    x, y = c[::2], c[1::2]

    A_1 = (x[3]-x[1])*(y[2]-y[1]) - (y[3]-y[1])*(x[2]-x[1])
    A_2 = (x[0]-x[1])*(y[2]-y[1]) - (y[0]-y[1])*(x[2]-x[1])
    A = A_1 / A_2

    B_1 = (-(x[3]-x[1])*(y[0]-y[1])) + (y[3]-y[1])*(x[0]-x[1])
    B_2 = (x[0]-x[1])*(y[2]-y[1]) - (y[0]-y[1])*(x[2]-x[1])
    B = B_1 / B_2
    
    if A >= 0 and B >= 0 and A+B >= 1:
        print('YES')
    else:
        print('NO')

Submission status: Accepted

Solution code:
import sys


class Vector(object):
    def __init__(self, _from, to):
        self.x = to[0]-_from[0]
        self.y = to[1]-_from[1]

    def cross(self, other: "Vector") -> float:
        return self.x * other.y - self.y * other.x


for a in (list(map(float, l.split(","))) for l in sys.stdin):
    points = [(x, y) for x, y in zip(a[::2], a[1::2])]
    sign = {Vector(p2, p3).cross(Vector(p2, p1)) > 0
            for p1, p2, p3 in zip(points, points[1:]+points, points[2:]+points)}
    print("YES" if len(sign) == 1 else "NO")

Submission status: Accepted

Solution code:
EPS = 0.0001

# しきい値を決める際に、ベクトル演算をするのだが、
# line, a,b で計算したときESPの誤差を許容する必要がある


# a, b, はラインの同一側にあるか。　-1, 0, 1
def atSameSide(a, b, line):
    sa = (line[1].real-line[0].real)*(a.imag-line[0].imag) \
         + (line[1].imag-line[0].imag)*(line[0].real-a.real);
    sb = (line[1].real-line[0].real)*(b.imag-line[0].imag) \
         + (line[1].imag-line[0].imag)*(line[0].real-b.real);
    if -EPS <= sa and sa <= EPS: return 0          # a in line
    if -EPS <= sb and sb <= EPS: return 0          # b in line
    if sa*sb >= 0: return 1           # a,b at same side
    return -1;
 
while True:
    try: p = list(map(float, input().split(',')))
    except: break
     
    p1 = complex(p[0], p[1])
    p2 = complex(p[2], p[3])
    p3 = complex(p[4], p[5])
    p4 = complex(p[6], p[7])
    if atSameSide(p2, p4, [p1, p3]) == -1 and \
       atSameSide(p1, p3, [p2, p4]) == -1: print('YES')
    else: print('NO')

Submission status: Accepted

Solution code:
import sys

def solve():
    for line in sys.stdin:
        xa,ya,xb,yb,xc,yc,xd,yd = map(float, line.split(','))
        
        def fac(x, y):
            if xa == xc:
                return x - xa
            else:
                return ((ya-yc)/(xa-xc))*(x-xa) - y + ya
        
        def fbd(x, y):
            if xb == xd:
                return x - xb
            else:
                return ((yb-yd)/(xb-xd))*(x-xb) - y + yb
        
        if fac(xb, yb) * fac(xd, yd) > 0:
            print('NO')
        elif fbd(xa, ya) * fbd(xc, yc) > 0:
            print('NO')
        else:
            print('YES')

if __name__ == "__main__":
    solve()

Submission status: Runtime Error

Solution code:
#encoding=utf-8
import sys

def inp():
	for i in sys.stdin:
		xa,ya,xb,yb,xc,yc,xd,yd = map(float, i.split(","))	
		print hantei(xa,ya,xb,yb,xc,yc,xd,yd)

def hantei(xa,ya,xb,yb,xc,yc,xd,yd):
	count = [0,0,0,0]
	a1 = (ya - yc)/(xa - yc)
	b1 = ya - a1*xa

	a2 = (yb - yd)/(xb - xd)
	b2 = yb - a2*xb

	if xb*a1+b1 > yb:
		count[0] += 1
	else:
		count[1] += 1
	if xd*a1+b1 > yd:
		count[0] += 1
	else:
		count[1] += 1
	if xa*a2+b2 > ya:
		count[2] += 1
	else:
		count[3] += 1
	if xc*a2+b2 > yc:
		count[2] += 1
	else:
		count[3] += 1

	for i in xrange(4):
		if count[i] != 1:
			return "NO"
		else:
			pass
	return "YES"

if __name__ == "__main__":
	inp()

Submission status: Runtime Error

Solution code:
import sys

def inp():
	for i in sys.stdin:
		xa,ya,xb,yb,xc,yc,xd,yd = map(float, i.split(","))	
		print hantei(xa,ya,xb,yb,xc,yc,xd,yd)

def hantei(xa,ya,xb,yb,xc,yc,xd,yd):
	count = [0,0,0,0]
	a1 = (ya - yc)/(xa - yc)
	b1 = ya - a1*xa

	a2 = (yb - yd)/(xb - xd)
	b2 = yb - a2*xb

	if xb*a1+b1 > yb:
		count[0] += 1
	else:
		count[1] += 1
	if xd*a1+b1 > yd:
		count[0] += 1
	else:
		count[1] += 1
	if xa*a2+b2 > ya:
		count[2] += 1
	else:
		count[3] += 1
	if xc*a2+b2 > yc:
		count[2] += 1
	else:
		count[3] += 1

	for i in xrange(4):
		if count[i] != 1:
			return "NO"
		else:
			pass
	return "YES"

if __name__ == "__main__":
	inp()

Submission status: Runtime Error

Solution code:
#encoding=utf-8
import sys

def inp():
	for i in sys.stdin:
		xa,ya,xb,yb,xc,yc,xd,yd = map(float, i.split(","))	
		print hantei(xa,ya,xb,yb,xc,yc,xd,yd)

def hantei(xa,ya,xb,yb,xc,yc,xd,yd):
	count = [0,0,0,0]
	a1 = (ya - yc)/(xa - yc)
	b1 = ya - a1*xa

	a2 = (yb - yd)/(xb - xd)
	b2 = yb - a2*xb

	if xb*a1+b1 > yb:
		count[0] += 1
	else:
		count[1] += 1
	if xd*a1+b1 > yd:
		count[0] += 1
	else:
		count[1] += 1
	if xa*a2+b2 > ya:
		count[2] += 1
	else:
		count[3] += 1
	if xc*a2+b2 > yc:
		count[2] += 1
	else:
		count[3] += 1

	for i in xrange(4):
		if count[i] != 1:
			return "NO"
		else:
			pass
	return "YES"

inp()

Submission status: Runtime Error

Solution code:
#encoding=utf-8
import sys


def hantei(xa,ya,xb,yb,xc,yc,xd,yd):
	count = [0,0,0,0]
	a1 = (ya - yc)/(xa - yc)
	b1 = ya - a1*xa

	a2 = (yb - yd)/(xb - xd)
	b2 = yb - a2*xb

	if xb*a1+b1 > yb:
		count[0] += 1
	else:
		count[1] += 1
	if xd*a1+b1 > yd:
		count[0] += 1
	else:
		count[1] += 1
	if xa*a2+b2 > ya:
		count[2] += 1
	else:
		count[3] += 1
	if xc*a2+b2 > yc:
		count[2] += 1
	else:
		count[3] += 1

	for i in xrange(4):
		if count[i] != 1:
			return "NO"
		else:
			pass
	return "YES"

for i in sys.stdin:
	xa,ya,xb,yb,xc,yc,xd,yd = map(float, i.split(","))	
	print hantei(xa,ya,xb,yb,xc,yc,xd,yd)

Submission status: Runtime Error

Solution code:
import math
def get_data():
    xa,ya,xb,yb,xc,yc,xd,yd = map(float,input().split(','))
    return xa,ya,xb,yb,xc,yc,xd,yd

def dist(x1,y1,x2,y2):
    d = ((x2-x1)**2 + (y2-y1)**2)**0.5
    return d

def lin(x1,y1,x2,y2):
    m = (y1-y2)/(x1-x2)
    n = (x1*y2-x2*y1)/(x1-x2)
    return m,n

def p_l(x0,y0,m,n):
    d = abs(y0-m*x0-n)/math.sqrt(1+m**2)
    return d

def convex(xa,ya,xb,yb,xc,yc,xd,yd):
    ac = dist(xa,ya,xc,yc)
    bd = dist(xb,yb,xd,yd)
    
    m1,n1 = lin(xb,yb,xd,yd)
    d1 = p_l(xa,ya,m1,n1)
    if ac < d1:
        print('NO')
        return 0
    
    m2,n2 = lin(xb,yb,xd,yd)
    d2 = p_l(xc,yc,m2,n2)
    if ac < d2:
        print('NO')
        return 0

    m3,n3 = lin(xa,ya,xc,yc)
    d3 = p_l(xb,yb,m3,n3)
    if bd < d3:
        print('NO')
        return 0
    
    m4,n4 = lin(xa,ya,xc,yc)
    d4 = p_l(xd,yd,m4,n4)
    if bd < d4:
        print('NO')
        return 0
    else:
        print('YES')
    return 0

while True:
    try:
        xa,ya,xb,yb,xc,yc,xd,yd = get_data()
        convex(xa,ya,xb,yb,xc,yc,xd,yd)
    except EOFError:
        break

Submission status: Runtime Error

Solution code:
import math
def get_data():
    xa,ya,xb,yb,xc,yc,xd,yd = map(float,input().split(','))
    return xa,ya,xb,yb,xc,yc,xd,yd

def dist(x1,y1,x2,y2):
    d = ((x2-x1)**2 + (y2-y1)**2)**0.5
    return d

def lin(x1,y1,x2,y2):
    m = (y1-y2)/(x1-x2)
    n = (x1*y2-x2*y1)/(x1-x2)
    return m,n

def p_l(x0,y0,m,n):
    d = abs(y0-m*x0-n)/math.sqrt(1+m**2)
    return d

def convex(xa,ya,xb,yb,xc,yc,xd,yd):
    ac = dist(xa,ya,xc,yc)
    bd = dist(xb,yb,xd,yd)
    
    m1,n1 = lin(xb,yb,xd,yd)
    d1 = p_l(xa,ya,m1,n1)
    if ac < d1:
        print('NO')
        return 0
    
    m2,n2 = lin(xb,yb,xd,yd)
    d2 = p_l(xc,yc,m2,n2)
    if ac < d2:
        print('NO')
        return 0

    m3,n3 = lin(xa,ya,xc,yc)
    d3 = p_l(xb,yb,m3,n3)
    if bd < d3:
        print('NO')
        return 0
    
    m4,n4 = lin(xa,ya,xc,yc)
    d4 = p_l(xd,yd,m4,n4)
    if bd < d4:
        print('NO')
        return 0
    
    print('YES')
    return 0

while True:
    try:
        xa,ya,xb,yb,xc,yc,xd,yd = get_data()
        convex(xa,ya,xb,yb,xc,yc,xd,yd)
    except EOFError:
        break

Submission status: Runtime Error

Solution code:
import math
def get_data():
    xa,ya,xb,yb,xc,yc,xd,yd = map(float,input().split(','))
    return xa,ya,xb,yb,xc,yc,xd,yd

def dist(x1,y1,x2,y2):
    d = ((x2-x1)**2 + (y2-y1)**2)**0.5
    return d

def lin(x1,y1,x2,y2):
    if x1 == x2:
        m = 10000000000    ac = dist(xa,ya,xc,yc)
    bd = dist(xb,yb,xd,yd)
    
    m1,n1 = lin(xb,yb,xd,yd)
    d1 = p_l(xa,ya,m1,n1)
    if ac < d1:
        print('NO')
        return 0
    
    m2,n2 = lin(xb,yb,xd,yd)
    d2 = p_l(xc,yc,m2,n2)
    if ac < d2:
        print('NO')
        return 0

    m3,n3 = lin(xa,ya,xc,yc)
    d3 = p_l(xb,yb,m3,n3)
    if bd < d3:
        print('NO')
        return 0
    
    m4,n4 = lin(xa,ya,xc,yc)
    d4 = p_l(xd,yd,m4,n4)
    if bd < d4:
        print('NO')
        return 0
    
    print('YES')
    return 0

while True:
    try:
        xa,ya,xb,yb,xc,yc,xd,yd = get_data()
        convex(xa,ya,xb,yb,xc,yc,xd,yd)
    except EOFError:
        break

Submission status: Runtime Error

Solution code:
import sys
for line in sys.stdin():
    p = list(map(float, line.split(',')))
    v = [p[i] - p[(i + 2) % 8] for i in range(8)]
    ip = [v[j] * v[(j + 3) % 8] - v[j + 1] * v[(j + 2) % 8] > 0 for j in range(0,8,2)]
    if sum(ip) == 0 or sum(ip) == 4:
        print('YES')
    else:
        print('NO')

Submission status: Runtime Error

Solution code:
class Vector2:
    """
    A simple 2D vector class.
    @Author:whitestone0811(Vir_MeL0)
    """
    def __init__(self,x,y):
        self.x=x
        self.y=y
    def __add__(self,other):
        return Vector2(self.x+other.x,self.y+other.y)
    def __sub__(self,other):
        return Vector2(self.x-other.x,self.y-other.y)
    def __mul__(self,other):
        if isinstance(other, Vector2):
            return self.x*other.x+self.y*other.y
        else:
            return Vector2(self.x*other,self.y*other)
    def __rmul__(self,other):
        if not isinstance(other,Vector2):
            return Vector2(self.x*other,self.y*other)
    def abs(self):
        return (self.x**2+self.y**2)**0.5
    def cos(self,other):
        return (self*other)/(self.abs()*other.abs())
    def __str__(self):
        return "[{0},{1}]".format(self.x,self.y)
    def __neg__(self):
        return Vector2(-self.x,-self.y)
#    
_in=input()
while _in!='':
    cors=[float(cor)for cor in _in.split(',')]
    vAB=Vector2(cors[2]-cors[0],cors[3]-cors[1])
    vBC=Vector2(cors[4]-cors[2],cors[5]-cors[3])
    vCD=Vector2(cors[6]-cors[4],cors[7]-cors[5])
    vDA=Vector2(cors[0]-cors[6],cors[1]-cors[7])
    cnv_a=True if(vAB-vDA)*(vAB+vBC)>0 else False
    cnv_b=True if(vBC-vAB)*(vBC+vCD)>0 else False
    cnv_c=True if(vCD-vBC)*(vCD+vDA)>0 else False
    cnv_d=True if(vDA-vCD)*(vDA+vAB)>0 else False
    print("YES" if cnv_a and cnv_b and cnv_c and cnv_d else "NO")
    _in=input()

Submission status: Runtime Error

Solution code:
def cross(p0, p1, p2):
  dx1, dx2 = p1[0] - p0[0], p2[0] - p0[0]
  dy1, dy2 = p1[1] - p0[1], p2[1] - p0[1]
  return True if dy2 * dx1 > dy1 * dx2 else False
 
while True:
  l = [float(x) for x in raw_input().split(',')]
  a = l[0:2]
  b = l[2:4]
  c = l[4:6]
  d = l[6:8]
  if((cross(a, c, b) != cross(a, c, d)) and (cross(b, d, a) != cross(b, d, c))):
    print 'YES'
  else:
    print 'NO'

Submission status: Runtime Error

Solution code:
def cross(p0, p1, p2):
  dx1, dx2 = p1[0] - p0[0], p2[0] - p0[0]
  dy1, dy2 = p1[1] - p0[1], p2[1] - p0[1]
  return dy2 * dx1 - dy1 * dx2
 
while True:
  line = raw_input()
  l = [float(r) for r in line.split(',')]
  a, b, c, d = l[0:2], l[2:4], l[4:6], l[6:8]
  print 'YES' if (cross(a, c, b) * cross(a, c, d)) < 0 and (cross(b, d, a) * cross(b, d, c) < 0) else 'NO'

Submission status: Runtime Error

Solution code:
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin
from collections import namedtuple
Point = namedtuple('Point', 'x y')

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

for line in stdin:
    it = (float(s) for s in line.split(','))
    A, B, C, D = (Point(next(it), next(it)) for _ in xrange(4))

    f = make_test(A, C)
    g = make_test(B, D)
    if f(B) == f(D) or g(A) == g(C):
        print('NO')
    else:
        print('YES')

Submission status: Runtime Error

Solution code:
import sys
def sign(x):
    if x>0: s=1
    elif x<0: s=-1
    else s=0
    return s

def f(p1,p2,p3):
    x1,y1 = p1
    s = sign((p3[1]-y1)*(p2[0]-x1)-(p2[1]-y1)*(p3[0]-x1))
    return s

for s in sys.stdin:
    D = map(float, s.split(","))
    p1 = D[0:2]; p2 = D[2:4]; p3 = D[4:6]; p4 = D[6:8]
    x = f(p1,p3,p2) != f(p1,p3,p4) and f(p2,p4,p1) != f(p2,p4,p3)
    print ["NO","YES"][x]

Submission status: Runtime Error

Solution code:
import sys
def sign(x):
    if x>0: s=1
    elif x<0: s=-1
    else s=0
    return s

def f(p1,p2,p3):
    x1,y1 = p1
    s = sign((p3[1]-y1)*(p2[0]-x1)-(p2[1]-y1)*(p3[0]-x1))
    return s

for s in sys.stdin:
    D = map(float, s.split(","))
    p1 = D[0:2]; p2 = D[2:4]; p3 = D[4:6]; p4 = D[6:8]
    print ["NO","YES"][f(p1,p3,p2) != f(p1,p3,p4) and f(p2,p4,p1) != f(p2,p4,p3)]