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: Wrong Answer

Solution code:
def sol(a1,b1,a2,b2,a3,b3):
    return (a3-a2)*b1-(b3-b2)*a1+a2*b3-a3-b2
while 1:
    try:
        x1,y1,x2,y2,x3,y3,x4,y4=map(float,raw_input().split())
        if sol(x1,y1,x2,y2,x4,y4)*sol(x3,y3,x2,y2,x4,y4)<0 and sol(x4,y4,x1,y1,x3,y3)*sol(x2,y2,x1,y1,x3,y3)<0:
            print 'YES'
        else:
            print 'NO'

    except:
        break

Submission status: Wrong Answer

Solution code:
def sol(a1,b1,a2,b2,a3,b3):
    return (a3-a2)*b1-(b3-b2)*a1+a2*b3-a3*b2
while 1:
    try:
        x1,y1,x2,y2,x3,y3,x4,y4=map(float,raw_input().split())
        if sol(x1,y1,x2,y2,x4,y4)*sol(x3,y3,x2,y2,x4,y4)<0 and sol(x4,y4,x1,y1,x3,y3)*sol(x2,y2,x1,y1,x3,y3)<0:
            print 'YES'
        else:
            print 'NO'

    except:
        break

Submission status: Wrong Answer

Solution code:
import fileinput

for line in fileinput.input():
    xa, ya, xb, yb, xc, yc, xd, yd = map(float, line.split(','))
    x = ((yb * xd - yd * xb) * (xc - xa) - (ya * xc - yc * xa) * (xd - xb)) \
        / ((yc - ya) * (xd - xb) - (yd - yb) * (xc - xa))
    print('NO' if (x - xa) * (x - xc) > 0 or (x - xb) * (x - xd) > 0 else 'YES')

Submission status: Wrong Answer

Solution code:
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 convex(xa,ya,xb,yb,xc,yc,xd,yd):
    dab = dist(xa,ya,xb,yb)
    dac = dist(xa,ya,xc,yc)
    dad = dist(xa,ya,xd,yd)
    dbc = dist(xb,yb,xc,yc)
    dbd = dist(xb,yb,xd,yd)
    dcd = dist(xc,yc,xd,yd)
    if dab > dac and dad > dac:
        print('NO')
    elif dab > dbd and dbc > dbd:
        print('NO')
    elif dbc > dac and dcd > dac:
        print('NO')
    elif dad > dbd and dcd > dbd:
        print('NO')
    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: Wrong Answer

Solution code:
def distance(ax,ay,bx,by):
    return (ax-bx)**2+(ay-by)**2

def yogen(plist, st):
    a = distance(plist[st], plist[st+1], plist[st+2], plist[st+3])
    b = distance(plist[st+2], plist[st+3], plist[st+4], plist[st+5])
    c = distance(plist[st+4], plist[st+5], plist[st+6], plist[st+7])
    return a+b-c >= 0

while True:
    try:
        points = list(map(float, input().split(",")))
        points.extend(points)
        points.extend(points)
        if yogen(points, 0) and yogen(points, 2) and yogen(points, 4) and yogen(points, 6): print("YES")
        else: print("NO")

    except EOFError: break

Submission status: Wrong Answer

Solution code:
def distance(ax,ay,bx,by):
    return (ax-bx)**2+(ay-by)**2

def yogen(plist, st):
    a = distance(plist[st], plist[st+1], plist[st+2], plist[st+3])
    b = distance(plist[st+2], plist[st+3], plist[st+4], plist[st+5])
    c = distance(plist[st+4], plist[st+5], plist[st], plist[st+1])
    return a-b+c >= 0

while True:
    try:
        points = list(map(float, input().split(",")))
        points.extend(points)
        if yogen(points, 0) and yogen(points, 2) and yogen(points, 4) and yogen(points, 6): print("YES")
        else: print("NO")

    except EOFError: break

Submission status: Wrong Answer

Solution code:
def distance(ax,ay,bx,by):
    return (ax-bx)**2+(ay-by)**2

def yogen(plist, st):
    a = distance(plist[st], plist[st+1], plist[st+2], plist[st+3])
    b = distance(plist[st+2], plist[st+3], plist[st+4], plist[st+5])
    c = distance(plist[st+4], plist[st+5], plist[st], plist[st+1])
    return a+b-c >= 0

while True:
    try:
        points = list(map(float, input().split(",")))
        points.extend(points)
        if yogen(points, 0) and yogen(points, 2) and yogen(points, 4) and yogen(points, 6): print("YES")
        else: print("NO")

    except EOFError: break

Submission status: Wrong Answer

Solution code:
while True:
    try:
        x1,y1,x2,y2,x3,y3,x4,y4 = map(float,input().split(','))
        p = (x3 - x4) * (y1 - y3) + (y3 - y4) * (x3 - x1)
        q = (x3 - x4) * (y2 - y3) + (y3 - y4) * (x3 - x2)
        r = (x1 - x2) * (y3 - y1) + (y1 - y2) * (x1 - x3)
        s = (x1 - x2) * (y4 - y1) + (y1 - y2) * (x1 - x4)
        if p * q < 0 and r * s < 0:
            print("YES")
        else:
            print("NO")
    except EOFError: break

Submission status: Wrong Answer

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]
        dot_a = -(ab[0]*da[0] + ab[1]*da[1])
        dot_b = -(bc[0]*ab[0] + bc[1]*ab[1])
        dot_c = -(cd[0]*bc[0] + cd[1]*bc[1])
        dot_d = -(da[0]*cd[0] + da[1]*cd[1])
        if dot_a*dot_b*dot_c*dot_d < 0:
            print("NO")
        else:
            print("YES")
    except:
        break

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def judge(p1,p2,p3,p4):
    t1 = (p1[0] - p3[0]) * (p2[1] - p1[1]) + (p1[1] - p3[1]) * (p1[0] - p2[0])
    t2 = (p1[0] - p3[0]) * (p4[1] - p1[1]) + (p1[1] - p3[1]) * (p1[0] - p4[0])
    t3 = (p2[0] - p4[0]) * (p1[1] - p2[1]) + (p2[1] - p4[1]) * (p2[0] - p1[0])
    t4 = (p2[0] - p4[0]) * (p3[1] - p2[1]) + (p2[1] - p4[1]) * (p2[0] - p3[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]
		print(A,B,C,D)
		if judge(A,B,C,D)==True or judge(A,D,B,C)==True :
			print("YES")
		else:
			print("NO")
	except EOFError:
		break

Submission status: Wrong Answer

Solution code:

import sys


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


class Quadrangle:
    def __init__(self, p1, p2, p3, p4):
        self.p1 = p1
        self.p2 = p2
        self.p3 = p3
        self.p4 = p4

    def isconvex(self):
        d1 = direction_of_rotation(self.p1, self.p2, self.p3)
        d2 = direction_of_rotation(self.p2, self.p3, self.p4)
        d3 = direction_of_rotation(self.p3, self.p4, self.p1)
        d4 = direction_of_rotation(self.p4, self.p1, self.p2)
        if d1 == d2 == d3 == d4:
            return 'YES'
        else:
            return 'NO'


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


for line in sys.stdin:
    a = map(float, line.split(','))
    p1 = Point(a[0], a[1])
    p2 = Point(a[2], a[2])
    p3 = Point(a[4], a[5])
    p4 = Point(a[6], a[7])
    q = Quadrangle(p1, p2, p3, p4)
    print q.isconvex()

Submission status: Wrong Answer

Solution code:
import sys


def main():
    for line in sys.stdin:
        p = map(float, line.strip().split(','))

        xa = p[0]
        ya = p[1]
        xb = p[2]
        yb = p[3]
        xc = p[4]
        yc = p[5]
        xd = p[6]
        yd = p[7]

        v1 = Vector2D(xb - xa, yb - ya)
        v2 = Vector2D(xc - xb, yc - yb)
        v3 = Vector2D(xd - xc, yd - yc)
        v4 = Vector2D(xa - xd, ya - yd)

        result = True

        if Vector2D.exterior_product(v1, v2) <= 0:
            result = False
        if Vector2D.exterior_product(v2, v3) <= 0:
            result = False
        if Vector2D.exterior_product(v3, v4) <= 0:
            result = False
        if Vector2D.exterior_product(v4, v1) <= 0:
            result = False

        print 'YES' if result else 'NO'


class Vector2D:

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

    @classmethod
    def inner_product(cls, v1, v2):
        return v1.x * v2.x + v1.y * v2.y

    @classmethod
    def exterior_product(cls, v1, v2):
        return v1.x * v2.y - v1.y * v2.x

    def __str__(self):
        return "(%f, %f)" % (self.x, self.y)


main()

Submission status: Wrong Answer

Solution code:
while True:
    try:
        ax,ay,bx,by,cx,cy,dx,dy = map(float, raw_input().split())
        if ax <=bx:
            if dx > (ax+cx)/2.0 or (dy-cy)*(dy-ay) > 0:
                print "NO"
            else:
                print "YES"
        else:
            if dx < (ax+cx)/2.0 or (dy-cy)*(dy-ay) > 0:
                print "NO"
            else:
                print "YES"
    except:
        break

Submission status: Wrong Answer

Solution code:
def f(x,y,x1,y1,x2,y2):
    if x1<=x2: 
        return (x2-x1)*y-(y2-y1)*x+x1*y2-x2*y1
    else:
        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(dx,dy,ax,ay,bx,by)*f(dx,dy,cx,cy,bx,by) < 0:
            if f(dx,dy,ax,ay,cx,cy)*f(bx,by,ax,ay,cx,cy) < 0:
                print "YES"
            else:
                print "NO"
        else:
                print "NO"
    except:
        break

Submission status: Wrong Answer

Solution code:
def f(x,y,x1,y1,x2,y2):
    if x1<=x2: return (x2-x1)*y-(y2-y1)*x+x1*y2-x2*y1
    else         : 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(dx,dy,ax,ay,bx,by)*f(dx,dy,cx,cy,bx,by) < 0:
            if f(dx,dy,ax,ay,cx,cy)*f(bx,by,ax,ay,cx,cy) < 0:
                print "YES"
            else:
                print "NO"
        else:
                print "NO"
    except:
        break

Submission status: Wrong Answer

Solution code:
def f(x,y,x1,y1,x2,y2):
    if x1<=x2: return (x2-x1)*y-(y2-y1)*x+x1*y2-x2*y1
    else         : 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(dx,dy,ax,ay,bx,by)*f(dx,dy,cx,cy,bx,by) < 0:
            if f(dx,dy,ax,ay,cx,cy)*f(bx,by,ax,ay,cx,cy) < 0:
                print "YES"
            else:
                print "NO"
        else:
                print "NO"
    except:
        break

Submission status: Wrong Answer

Solution code:
def f(x,y,x1,y1,x2,y2):
    if x1<=x2: return (x2-x1)*y-(y2-y1)*x+x1*y2-x2*y1
    else         : 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(dx,dy,ax,ay,bx,by)*f(dx,dy,cx,cy,bx,by) < 0.0:
            if f(dx,dy,ax,ay,cx,cy)*f(bx,by,ax,ay,cx,cy) < 0.0:
                print "YES"
            else:
                print "NO"
        else:
                print "NO"
    except:
        break

Submission status: Accepted

Solution code:
import sys
import math
for line in sys.stdin:
    xa,ya,xb,yb,xc,yc,xd,yd = [float(i) for i in line.split(",")]
    
    # 図形の凸性:各頂点における外積を計算し、一つでも符号の異なるものがあれば非凸
    ab = (xb-xa,yb-ya)
    bc = (xc-xb,yc-yb)
    cd = (xd-xc,yd-yc)
    da = (xa-xd,ya-yd)
    va = da[0]*ab[1] - da[1]*ab[0]
    vb = ab[0]*bc[1] - ab[1]*bc[0]
    vc = bc[0]*cd[1] - bc[1]*cd[0]
    vd = cd[0]*da[1] - cd[1]*da[0]
    if all(map(lambda x:x/abs(x) == 1.0,[va,vb,vc,vd])) or all(map(lambda x:x/abs(x) == -1.0,[va,vb,vc,vd])):
        print("YES")
    else:
        print("NO")

Submission status: Accepted

Solution code:
from sys import stdin

while(True):
    try:
        xa,ya,xb,yb,xc,yc,xd,yd = map(float, stdin.readline().split(","))
        ab = [xb-xa,yb-ya]
        bc = [xc-xb,yc-yb]
        cd = [xd-xc,yd-yc]
        da = [xa-xd,ya-yd]
        cr1 = ab[0]*bc[1] - ab[1]*bc[0]
        cr2 = bc[0]*cd[1] - bc[1]*cd[0]
        cr3 = cd[0]*da[1] - cd[1]*da[0]
        cr4 = da[0]*ab[1] - da[1]*ab[0]
        if (cr1<0 and cr2<0 and cr3<0 and cr4<0) or (cr1>0 and cr2>0 and cr3>0 and cr4>0):
            print("YES")
        else:
            print("NO")
    except:
        break

Submission status: Accepted

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

import sys

def crossz(v1,v2):
  return v1[0]*v2[1]-v1[1]*v2[0]

for s in sys.stdin:
  d = map(float,s.split(","))
  xa,ya,xb,yb,xc,yc,xd,yd = d[0],d[1],d[2],d[3],d[4],d[5],d[6],d[7]
  vab = [xb-xa,yb-ya]
  vbc = [xc-xb,yc-yb]
  vcd = [xd-xc,yd-yc]
  vda = [xa-xd,ya-yd]
  dotb = crossz(vab,vbc)
  dotc = crossz(vbc,vcd)
  dotd = crossz(vcd,vda)
  dota = crossz(vda,vab)
  if dotb*dotc*dotd*dota > 0:
    print "YES"
  else:
    print "NO"

Submission status: Accepted

Solution code:
import collections

Point = collections.namedtuple("Point", "x y")
Line = collections.namedtuple("Line", "first second")


def cross(line1, line2):
    def get_s(a, b, c):
        x1 = a.x - c.x
        x2 = b.x - c.x
        y1 = a.y - c.y
        y2 = b.y - c.y
        return (x1 * y2) - (x2 * y1)

    s1 = get_s(line1.first, line1.second, line2.first)
    s2 = get_s(line1.first, line1.second, line2.second)

    if not (s1 > 0) ^ (s2 > 0):
        return False

    s3 = get_s(line2.first, line2.second, line1.first)
    s4 = get_s(line2.first, line2.second, line1.second)

    if not (s3 > 0) ^ (s4 > 0):
        return False

    return True


if __name__ == '__main__':
    while 1:
        try:
            xa, ya, xb, yb, xc, yc, xd, yd = map(float, raw_input().split(','))
            A = Point(xa, ya)
            B = Point(xb, yb)
            C = Point(xc, yc)
            D = Point(xd, yd)
            points = [A, B, C, D]
            f = False
            for i in xrange(4):
                line1 = Line(points[(i + 0) % 4], points[(i + 2) % 4])
                line2 = Line(points[(i + 1) % 4], points[(i + 3) % 4])
                if not cross(line1, line2):
                    f = True

            for i in xrange(4):
                line1 = Line(points[i], points[(i + 1) % 4])
                line2 = Line(points[(i + 2) % 4], points[(i + 3) % 4])
                if cross(line1, line2):
                    f = True

            if f:
                print "NO"
            else:
                print "YES"
        except EOFError:
            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 is_convex(a, b, c, d):
    v1 = cross(a - b, b - c)
    v2 = cross(b - c, c - d)
    v3 = cross(c - d, d - a)
    v4 = cross(d - a, a - b)    
    return 0 < v1 * v2 and 0 < v2 * v3 and 0 < v3 * v4

for line in f:
    a, b, c, d = [x + y *1j for x, y in take2(map(float, line.split(',')))]
    
    print('YES' if is_convex(a,b,c,d) 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:
    xa,ya,xb,yb,xc,yc,xd,yd=map(float,dataset.split(","))
    ABC=S(xa,ya,xb,yb,xc,yc)
    BCD=S(xb,yb,xc,yc,xd,yd)
    CDA=S(xc,yc,xd,yd,xa,ya)
    DAB=S(xd,yd,xa,ya,xb,yb)
    if ABC>0 and BCD>0 and CDA>0 and DAB>0:
        print "YES"
    elif ABC<0 and BCD<0 and CDA<0 and DAB<0:
        print "YES"
    else:
        print "NO"

Submission status: Accepted

Solution code:
import sys

for s in sys.stdin:
	pos = list(map(float, s.split(',')))
	sideB = (pos[3]-pos[1])*(pos[0]-pos[4]) - (pos[2]-pos[0])*(pos[1]-pos[5])
	sideD = (pos[7]-pos[1])*(pos[0]-pos[4]) - (pos[6]-pos[0])*(pos[1]-pos[5])
	abxcd = sideB * sideD
	sideA = (pos[1]-pos[3])*(pos[2]-pos[6]) - (pos[0]-pos[2])*(pos[3]-pos[7])
	sideC = (pos[5]-pos[3])*(pos[2]-pos[6]) - (pos[4]-pos[2])*(pos[3]-pos[7])
	cdxab = sideA * sideC

	if abxcd < 0 and cdxab < 0:
		print("YES")
	else:
		print("NO")

Submission status: Accepted

Solution code:
def sol(a1,b1,a2,b2,a3,b3):
    return (a3-a2)*b1-(b3-b2)*a1+a2*b3-a3*b2
while 1:
    try:
        x1,y1,x2,y2,x3,y3,x4,y4=map(float,raw_input().split(','))
        if sol(x1,y1,x2,y2,x4,y4)*sol(x3,y3,x2,y2,x4,y4)<0 and sol(x4,y4,x1,y1,x3,y3)*sol(x2,y2,x1,y1,x3,y3)<0:
            print 'YES'
        else:
            print 'NO'

    except:
        break

Submission status: Accepted

Solution code:
import fileinput

for line in fileinput.input():
    xa, ya, xb, yb, xc, yc, xd, yd = map(float, line.split(','))
    xab, yab, xbc, ybc, xcd, ycd, xda, yda = xb - xa, yb - ya, xc - xb, yc - yb, xd - xc, yd - yc, xa - xd, ya - yd
    ab = xab * ybc - xbc * yab
    bc = xbc * ycd - xcd * ybc
    cd = xcd * yda - xda * ycd
    da = xda * yab - xab * yda
    print('YES' if ab * bc > 0 and ab * cd > 0 and ab * da > 0 else 'NO')

Submission status: Accepted

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

def is_convex(points):
    n = len(points)
    x = points[1] - points[0]
    y = points[2] - points[1]
    c0 = cross(x, y)
    for i in range(1, n):
        x = y
        y = points[(i+2)%n] - points[(i+1)%n]
        if c0 * cross(x, y) < 0:
            return False
    return True
        

import sys

for line in sys.stdin:
    li = list(map(float, line.split(',')))
    p = []
    for i in range(0, len(li), 2):
        p.append(complex(li[i], li[i+1]))
    if is_convex(p):
        print('YES')
    else:
        print('NO')

Submission status: Accepted

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

import sys

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

def is_same_side(p1, p2, p3, p4):
    a = -(p1.y-p2.y)
    b = p1.x-p2.x
    c = p2.x*p1.y-p2.y*p1.x
    if (a*p3.x+b*p3.y+c) * (a*p4.x+b*p4.y+c) >= 0:
        return True
    else:
        return False

for line in sys.stdin:
    x1, y1, x2, y2, x3, y3, x4, y4 = map(float, line.split(','))
    p1 = Point_class(x1, y1)
    p2 = Point_class(x2, y2)
    p3 = Point_class(x3, y3)
    p4 = Point_class(x4, y4)
    if is_same_side(p1, p3, p2, p4) or is_same_side(p2, p4, p1, p3):
        print "NO"
    else:
        print "YES"

Submission status: Accepted

Solution code:
import sys
def angleis(p1, p2):
    return True if p1[0] * p2[1] - p1[1] * p2[0] > 0 else False

Ps = sys.stdin.readlines()
for P in Ps:
    xa, ya, xb, yb, xc, yc, xd, yd = map(float, P.split(','))
    p = [[xb-xa, yb-ya],[xc-xb, yc-yb],[xd-xc, yd-yc],[xa-xd, ya-yd],[xb-xa, yb-ya]]
    a = []
    for i in range(4):
        a.append(angleis(p[i], p[i+1]))
    if a.count(True) == 0 or a.count(True) == 4:
        print('YES')
    else :
        print('NO')

Submission status: Accepted

Solution code:
while True:
    try:
        p = list(map(float, input().split(',')))
    except:
        break
    v = [p[i] - p[(i + 2) % 8] for i in range(8)]
    ip = [v[i] * v[(i + 3) % 8] - v[i + 1] * v[(i + 2) % 8] > 0 for i in range(0,8,2)]
    if sum(ip) == 0 or sum(ip) == 4:
        print('YES')
    else:
        print('NO')

Submission status: Accepted

Solution code:
import math


def eq(x, y):
    return abs(x - y) <= 10e-10


def get_r(_a, _b, _c):
    return math.acos((-_a ** 2 + _b ** 2 + _c ** 2) / (2 * _b * _c))


def _len(_ax, _ay, _bx, _by):
    return math.sqrt((_ax - _bx) ** 2 + (_ay - _by) ** 2)

try:
    while 1:

        xa,ya,xb,yb,xc,yc,xd,yd = map(float, input().split(','))

        ab = _len(xa,ya,xb,yb)
        bc = _len(xc,yc,xb,yb)
        cd = _len(xc,yc,xd,yd)
        ad = _len(xa,ya,xd,yd)

        bd = _len(xd,yd,xb,yb)
        ac = _len(xa,ya,xc,yc)

        A = get_r(bd, ab, ad)
        B = get_r(ac, ab, bc)
        C = get_r(bd, bc, cd)
        D = get_r(ac, ad, cd)

        if eq(A + B + C + D, 2 * math.pi):
            print("YES")
        else:
            print("NO")

except:
    pass

Submission status: Accepted

Solution code:
import math
while True:
    try:
        xa, ya, xb, yb, xc, yc, xd, yd = map(float, input().split(','))
    except:
        break
    vecs = [(xb - xa, yb - ya), (xc - xb, yc - yb), (xd - xc, yd - yc), (xa - xd, ya - yd)]
    angles = [(math.atan2(*vecs[(i + 1) % 4][::-1]) - math.atan2(*vecs[i][::-1])) % (2 * math.pi) for i in range(4)]
    print('YES' if max(angles) < math.pi or min(angles) > math.pi else 'NO')

Submission status: Accepted

Solution code:
import sys
#for line in sys.stdin:
def cross(ax,ay,bx,by):
	return ax*by-ay*bx

def check(ax,ay,bx,by,cx,cy,dx,dy):
	a=cross(dx-ax,dy-ay,bx-ax,by-ay)
	b=cross(ax-bx,ay-by,cx-bx,cy-by)
	c=cross(bx-cx,by-cy,dx-cx,dy-cy)
	d=cross(cx-dx,cy-dy,ax-dx,ay-dy)
	if a*b<0 or a*c<0 or a*d<0:
		return False
	else:
		return True

if __name__=="__main__":
	"""while True:
		line=raw_input()
	"""
	for line in sys.stdin:
		a=map(float,line.split(","))
		if check(a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7]):
			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(","))
        A1,A2,B1,B2,C1,C2,D1,D2 = x1,y1,x2,y2,x3,y3,xp,yp
        
        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("NO")
        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("NO")
        else:
            x1,y1,x2,y2,x3,y3,xp,yp = A1,A2,B1,B2,D1,D2,C1,C2
            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("NO")
            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("NO")
            else:
                x1,y1,x2,y2,x3,y3,xp,yp = A1,A2,D1,D2,C1,C2,B1,B2
                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("NO")
                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("NO")
                else:
                    x1,y1,x2,y2,x3,y3,xp,yp = D1,D2,B1,B2,C1,C2,A1,A2
                    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("NO")
                    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("NO")
                    else:
                        print("YES")

            
    except EOFError:
        break

Submission status: Accepted

Solution code:
def op(a,b):
    return(a[0]*b[1]- a[1]*b[0])

def vec(a,b):
    return(b[0]-a[0],b[1]- a[1])

while True:
    try:
        xa,ya,xb,yb,xc,yc,xd,yd = list(map(float,input().strip().split(',')))
        a = (xa,ya)
        b = (xb,yb)
        c = (xc,yc)
        d = (xd,yd)
        p1 = op(vec(a,b), vec(b,c))
        p2 = op(vec(b,c), vec(c,d))
        p3 = op(vec(c,d), vec(d,a))
        p4 = op(vec(d,a), vec(a,b))
        if (p1 > 0 and p2 > 0 and p3 > 0 and p4 > 0) or (p1 < 0 and p2 < 0 and p3 < 0 and p4 < 0):
            print("YES") 
        else:
            print("NO") 

    except EOFError:
        break

Submission status: Accepted

Solution code:
def f(x1,y1,x2,y2,x3,y3,x4,y4):
    p = (x3 - x4) * (y1 - y3) + (y3 - y4) * (x3 - x1)
    q = (x3 - x4) * (y2 - y3) + (y3 - y4) * (x3 - x2)
    r = (x1 - x2) * (y3 - y1) + (y1 - y2) * (x1 - x3)
    s = (x1 - x2) * (y4 - y1) + (y1 - y2) * (x1 - x4)
    return p * q < 0 and r * s < 0

while True:
    try:
        x1,y1,x2,y2,x3,y3,x4,y4 = map(float,input().split(','))
    except EOFError:
        break
    if f(x1,y1,x3,y3,x2,y2,x4,y4):
        print('YES')
    else:
        print('NO')

Submission status: Accepted

Solution code:
while True:
    try:
        x1,y1,x2,y2,x3,y3,x4,y4 = map(float,input().split(','))
        p = (x3 - x4) * (y1 - y3) + (y3 - y4) * (x3 - x1)
        q = (x3 - x4) * (y2 - y3) + (y3 - y4) * (x3 - x2)
        r = (x1 - x2) * (y3 - y1) + (y1 - y2) * (x1 - x3)
        s = (x1 - x2) * (y4 - y1) + (y1 - y2) * (x1 - x4)
        if p * q < 0 or r * s < 0:
            print("NO")
        else:
            print("YES")
    except EOFError: break

Submission status: Accepted

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

import sys
import os
import math


def cross(v1, v2):
    return v1[0] * v2[1] - v1[1] * v2[0]

def sign(v):
    if v >= 0:
        return 1
    else:
        return -1

for s in sys.stdin:
    ax, ay, bx, by, cx, cy, dx, dy = map(float, s.split(','))

    AB = (bx - ax, by - ay)
    BC = (cx - bx, cy - by)
    CD = (dx - cx, dy - cy)
    DA = (ax - dx, ay - dy)

    c0 = cross(AB, BC)
    c1 = cross(BC, CD)
    c2 = cross(CD, DA)
    c3 = cross(DA, AB)

    if sign(c0) == sign(c1) == sign(c2) == sign(c3):
        print('YES')
    else:
        print('NO')

Submission status: Accepted

Solution code:
import sys
for line in sys.stdin:
    try:
        p = list(map(float, line.split(',')))
    except:
        break
    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: Accepted

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)
#  
import sys  
lines=sys.stdin
for _in in lines:
    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")

Submission status: Accepted

Solution code:
# Aizu Problem 0035: Is it Convex?
#
import sys, math, os

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


def distance(p1, p2):
    return math.sqrt((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2)

def is_to_the_left(p1, p2, p3):
    # determine whether point p3 is to the left from the line from p1 to p2
    position = (p2[0] - p1[0]) * (p3[1] - p1[1]) - (p2[1] - p1[1]) * (p3[0] - p1[0])
    return position < 0


def jarvis(points):
    # determine convex hull by Jarvis' algorithm:
    max_y = max([p[1] for p in points])
    pointOnHull = [p for p in points if p[1] == max_y][0]
    convex_hull = [pointOnHull]
    while len(convex_hull) == 1 or convex_hull[-1] != convex_hull[0]:
        p = convex_hull[-1]
        endpoint = points[0]
        for j in range(len(points)):
            if endpoint == pointOnHull or is_to_the_left(p, endpoint, points[j]):
                endpoint = points[j]
        pointOnHull = endpoint
        convex_hull.append(pointOnHull)
    return convex_hull[::-1]
    

def convex_hull(points):
    hull = jarvis(points)
    length = 0
    line2 = ""
    for i in range(len(hull) - 1):
        p1, p2 = hull[i], hull[i+1]
        line2 += "(" + str(p1[0]) + "," + str(p1[1]) + ") "
    line2 += "(" + str(hull[-1][0]) + "," + str(hull[-1][1]) + ")"
    print(line2)
    

while True:
    try:
        x1, y1, x2, y2, x3, y3, x4, y4 = [float(_) for _ in input().split(',')]
    except EOFError:
        break
    print("YES" if len(jarvis([[x1, y1], [x2, y2], [x3, y3], [x4, y4]])) == 5 else "NO")

Submission status: Accepted

Solution code:
def is_on_the_same_side(p0, p1, p2, p3):
    s2 = (p1[0]-p0[0]) * (p2[1]-p0[1]) - (p2[0]-p0[0]) * (p1[1]-p0[1])
    s3 = (p1[0]-p0[0]) * (p3[1]-p0[1]) - (p3[0]-p0[0]) * (p1[1]-p0[1])
    if s2 * s3 > 0:
        return True
    else:
        return False

while True:
    try:
        data = list(map(float, input().split(',')))
        a = data[0:2]
        b = data[2:4]
        c = data[4:6]
        d = data[6:8]

        if not is_on_the_same_side(a, c, b, d) and is_on_the_same_side(b, c, a, d) and is_on_the_same_side(a, b, c, d):
            print('YES')
        else:
            print('NO')
    except:
        break