Problem:


凸 n 角形の面積

凸 n 角形（すべての頂点の内角が 180 度未満である多角形、要するにへこんでいない多角形のこと）の頂点の座標を読んで、その面積を出力するプログラムを作成してください。頂点には辺のつながりの順序に従って頂点 1、頂点 2、頂点 3、‥‥頂点 n という名前がついています。

ただし、 n は 3 以上 20 以下とします。また、次の、三角形の 3 辺の長さ a, b, c から面積 S を求める公式を使ってもかまいません。

入力

入力は以下の形式で与えられます。

x1,y1
x2,y2
:
xn,yn

xi, yi はそれぞれ頂点 i の x 座標, y 座標を表す実数です。

出力

面積 S （実数）を１行に出力します。
出力は 0.000001 以下の誤差を含んでもかまいません。

Sample Input

0.0,0.0
0.0,1.0 
1.0,1.0 
2.0,0.0 
1.0,-1.0 

Output for the Sample Input

2.500000



Sample input:
0.0,0.0
0.0,1.0
1.0,1.0
2.0,0.0
1.0,-1.0


Sample output:
2.500000

Submission status: Accepted

Solution code:
import sys
readlines = sys.stdin.readlines
write = sys.stdout.write
def solve():
    P = []
    for line in readlines():
        x, y = map(float, line.split(","))
        P.append((x, y))
    N = len(P)
    s = 0
    for i in range(N):
        x0, y0 = P[i-1]; x1, y1 = P[i]
        s += x0*y1 - x1*y0
    write("%.16f\n" % (abs(s)/2))
solve()

Submission status: Accepted

Solution code:
def solve():
    from sys import stdin
    lines = stdin
    
    x1, y1 = map(float, lines.readline().split(','))
    x2, y2 = map(float, lines.readline().split(','))
    
    vx1 = x2 - x1
    vy1 = y2 - y1
    
    area = 0
    for line in lines:
        x3, y3 = map(float, line.split(','))
        
        vx2 = x3 - x1
        vy2 = y3 - y1
        
        area += abs(vx1 * vy2 - vy1 * vx2) / 2
        
        vx1, vy1 = vx2, vy2
    
    print(area)

solve()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
'''
所要時間は、分位であった。
'''


# ライブラリのインポート
#import re
import sys
input = sys.stdin.readline
#import heapq
#import bisect
#from collections import deque
#import math

def main():
    P = []
    for line in sys.stdin:
        x, y = map(float, line.strip().split(','))
        P.append(complex(x, y))
    ans = areap(P)
    print(abs(ans))

def areap(P):
    s = 0
    n = len(P)
    for i in range(1,n-1):
        a, b, c = P[0],P[i],P[i+1]
        s += cdot(b-a,c-a)
    return s/2

def cdot(x, y):
    return (x.conjugate() * y).imag

    


    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# coding=utf-8

###
### for python program
###

import sys
import math

# math class
class mymath:
    ### pi
    pi = 3.14159265358979323846264338

    ### Prime Number
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []

        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist

    def pnum_check(self, n):
        if (n==1):
            return False
        elif (n==2):
            return True
        else:
            for x in range(2,n):
                if(n % x==0):
                    return False
            return True

    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    ### LCM
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

    ### Mat Multiplication
    def mul(self, A, B):
        ans = []
        for a in A:
            c = 0
            for j, row in enumerate(a):
                c += row*B[j]
            ans.append(c)
        return ans
    
    ### intチェック
    def is_integer(self, n):
        try:
            float(n)
        except ValueError:
            return False
        else:
            return float(n).is_integer()

    ### 幾何学問題用
    def dist(self, A, B):
        d = 0
        for i in range(len(A)):
            d += (A[i]-B[i])**2            
        d = d**(1/2)
        return d

    ### 絶対値
    def abs(self, n):
        if n >= 0:
            return n
        else:
            return -n   

mymath = mymath()

### output class
class output:
    ### list
    def list(self, l):
        l = list(l)
        #print(" ", end="")
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()

### input sample
#i = input()
#N = int(input())
#A, B, C = [x for x in input().split()]
#N, K = [int(x) for x in input().split()]
#inlist = [int(w) for w in input().split()]

#R = float(input())
#A.append(list(map(int,input().split())))

#for line in sys.stdin.readlines():
#    x, y = [int(temp) for temp in line.split()]

#abc list
#abc = [chr(ord('a') + i) for i in range(26)]

### output sample
# print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
# print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
# print(" {}".format(i), end="")

def printA(A):
    N = len(A)
    for i, n in enumerate(A):
        print(n, end='')
        if i != N-1:
            print(' ', end='')
    print()

# リスト内包表記 ifあり
# [x-k if x != 0 else x for x in C]

# ソート（代入する必要なし）
# N.sort()

# 10000個の素数リスト
# P = mymath.pnum_eratosthenes(105000)

def get_input(s=' '):
    N = []
    while True:
        try:
            #N.append(input())
            #N.append(int(input()))
            #N.append(float(input()))
            #N.append([int(x) for x in input().split(s)])
            N.append([float(x) for x in input().split(s)])
        except EOFError:
            break
    return N

### 0079

def CalcArea(A, B, C):
    a = ((A[0]-B[0])**2+(A[1]-B[1])**2)**0.5
    b = ((B[0]-C[0])**2+(B[1]-C[1])**2)**0.5
    c = ((C[0]-A[0])**2+(C[1]-A[1])**2)**0.5
    z = (a+b+c)/2
    return (z*(z-a)*(z-b)*(z-c))**0.5

D = get_input(',')

ans = 0.0

for i in range(1, len(D)-1):
    ans += CalcArea(D[0], D[i], D[i+1])

print(ans)

Submission status: Accepted

Solution code:
import sys
def area_of_triangle(x, y, z):
    return ((y[0]-x[0])*(z[1]-x[1]) - (z[0]-x[0])*(y[1]-x[1])) / 2
p = [list(map(float, line.split(','))) for line in sys.stdin]
print(sum([area_of_triangle(p[0], p[i], p[i+1]) for i in range(1, len(p) - 1)]))

Submission status: Accepted

Solution code:
import math
import cmath

def area(b,c):
    theta = cmath.phase(b)
    C = (c)*complex(math.cos(-theta),math.sin(-theta))
    return abs(b)*C.imag/2

P = []
try:
    while True:
        x,y = map(float,input().split(','))
        P.append(complex(x,y))
except EOFError:
    pass
except ValueError:
    pass
P.append(P[0])
N = len(P)
total = 0.0
for i in range(0,N-1):
    b,c = P[i],P[i+1]
    total += area(b,c)
print(abs(total))

Submission status: Accepted

Solution code:
import math
import cmath
def cross_product(a,b):
    return (a.conjugate()*b).imag
L = []
try:
    while True:
        x,y = map(float,input().split(','))
        L.append(complex(x,y))
except EOFError:
    pass
N = len(L)
S = 0
for i in range(1,N-1):
    a,b,c = L[0],L[i],L[i+1]
    S += abs(cross_product(b-a,c-a))/2
print(S)

Submission status: Accepted

Solution code:
p1=complex(*list(map(float,input().split(','))))
p2=complex(*list(map(float,input().split(','))))
ans=0
def area(p,q,r):
    return ((p-r).conjugate()*(q-r)).imag/2
try:
    while True:
        p3=complex(*list(map(float,input().split(','))))
        ans+=area(p1,p2,p3)
        p2=p3
except EOFError: print(abs(ans))

Submission status: Accepted

Solution code:
def norm(c):
    a = abs(c)
    return a*a
def dot_product(a,b):
    return (a.conjugate()*b).real
def cross_product(a,b):
    return (a.conjugate()*b).imag
def projection(p,b):
    return b*dot_product(p,b)/norm(b)

P = []
try:
    while True:
        x,y = map(float,input().split(','))
        P.append(complex(x,y))
except EOFError:
    pass

N = len(P)
total = 0.0
for i in range(1,N-1):
    a,b,c = P[0],P[i],P[i+1]
    S = abs(cross_product(b-a,c-a))/2
    total += S

print("%.6f" % (total))

Submission status: Accepted

Solution code:
number = []
answer = 0
while 1:
    try:
        x, y = map(float, input().split(","))
        number.append((x, y))
    except:
        number.append(number[0])
        for i in range(len(number)-1):
            answer += (number[i][0] - number[i + 1][0]) * (number[i][1] + number[i+1][1])
        if answer < 0:
            answer = answer * (-1)
        print("{:.6f}".format(answer / 2))
        break

Submission status: Accepted

Solution code:
ans=0
x,y=map(float,input().split(","))
k1,k2=map(float,input().split(","))
while 1:
    try:
        k3,k4=map(float,input().split(","))
        a=((k1-x)**2+(k2-y)**2)**0.5
        b=((k3-x)**2+(k4-y)**2)**0.5
        c=((k1-k3)**2+(k2-k4)**2)**0.5
        z=(a+b+c)/2
        ans+=(z*(z-a)*(z-b)*(z-c))**0.5
        k1,k2=k3,k4
    except:break
print(ans)

Submission status: Accepted

Solution code:
from math import sqrt
x = []
y = []
while(1):
    try:
        a = [float(i) for i in input().split(",")]
        x.append(a[0])
        y.append(a[1])
    except EOFError:
        break
n = len(x)
S = 0

for i in range(n-2):
    if i == 0:
        a = sqrt((x[1]- x[0])**2 + (y[1]-y[0])**2)
    b = sqrt((x[i+2]- x[i+1])**2 + (y[i+2]-y[i+1])**2)
    c = sqrt((x[i+2]- x[0])**2 + (y[i+2]-y[0])**2)
    z = (a+b+c)/2
    s = sqrt(z*(z-a)*(z-b)*(z-c))
    S = S + s
    a = c

print("{:.6f}".format(S))

Submission status: Accepted

Solution code:
import cmath
def norm(c):
    a = abs(c)
    return a*a
def dot_product(a,b):
    return (a.conjugate()*b).real
def cross_product(a,b):
    return (a.conjugate()*b).imag
def projection(p,b):
    return b*dot_product(p,b)/norm(b)
P = []
try:
    while True:
        x,y = map(float,input().strip().split(","))
        P.append(complex(x,y))
except EOFError:
    pass
N = len(P)
total = 0.0
for i in range(1,N-1):
    a,b,c = P[0],P[i],P[i+1]
    total += cross_product(b-a,c-a)
print("%.6f" % (abs(total)/2.0))

Submission status: Accepted

Solution code:
def read():
    return(list(map(float,input().split(","))))
def triArea(va,vb,vc):
    return(abs((va[0]-vc[0])*(vb[1]-vc[1])-(va[1]-vc[1])*(vb[0]-vc[0]))/2)
v1=read()
va=read()
vb=read()
s=triArea(v1,va,vb)
while 1:
    try:
        va=vb
        vb=read()
        s+=triArea(v1,va,vb)
    except:break
print(s)

Submission status: Runtime Error

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

def area_polygon(points):
    area = 0
    n = len(points)
    for i in range(n + 1):
        area += cross(points[i], points[(i+1)%n])
    return area / 2
    
    
import sys

p = []
for line in sys.stdin:
    p.append(list(map(float, line.split(','))))

print(area_polygon(p))

Submission status: Runtime Error

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

def area_polygon(points):
    area = 0
    n = len(points)
    for i in range(n):
        area += cross(points[i], points[(i+1)%n])
    return area / 2
    
    
import sys

p = []
for line in sys.stdin:
    p.append(list(map(float, line.split(','))))

print(area_polygon(p))

Submission status: Runtime Error

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

def area_polygon(points):
    area = 0
    n = len(points)
    for i in range(n):
        area += cross(points[i], points[(i+1)%n])
    return area / 2
    
    
import sys

p = []
for line in sys.stdin:
    p.append(list(map(float, line.split(','))))

print("{0:06f}".format(area_polygon(p)))

Submission status: Runtime Error

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

def area_polygon(points):
    area = 0
    n = len(points)
    for i in range(n):
        area += cross(points[i], points[(i+1)%n])
    return area / 2
    
    
import sys

p = []
for line in sys.stdin:
    if line == "":
        break
    p.append(list(map(float, line.split(','))))

print("{0:06f}".format(area_polygon(p)))

Submission status: Runtime Error

Solution code:
def cross(x, y):
    return (x.conjugate() * y).imag
 
def area_polygon(points):
    area = 0
    n = len(points)
    for i in range(n):
        area += cross(points[i], points[(i+1)%n])
    return area / 2
     
     
import sys
 
p = []
for line in sys.stdin:
    x, y = map(float, line.split(','))
    p.append(x+y*1j))
 
print(abs(area_polygon(p)))

Submission status: Runtime Error

Solution code:
def cross(x, y):
    return (x.conjugate() * y).imag
 
def area_polygon(points):
    area = 0
    n = len(points)
    for i in range(n):
        area += cross(points[i], points[(i+1)%n])
    return area / 2
     
     
import sys
 
p = []
for line in sys.stdin:
    x, y = map(float, line.split(','))
    p.append(x+y*j))
 
print(abs(area_polygon(p)))

Submission status: Runtime Error

Solution code:
import math
def op(u,v):
    return (conjugate(u)*v).imag

f = []
while True:
    try:
        st = input().strip().split(',')
        x,y = list(map(float,st ))
        f.append(x + y*1j)
    except EOFError:
        break

s = 0.0
fo = f[0]
for j in range(2,len(f)):
    i = j - 1
    s += op(i-fo,j-fo)/2.0
print("%.6f" % abs(ss))

Submission status: Runtime Error

Solution code:
import sys
s=0
p=[list(map(float,e.split(',')))for e in sys.stdin]
x,y=p[0]
print(abs(sum((p[i][0]-x)*(p[i+1][1]-y)-(p[i][1]-y)*(p[i+1][0]-x))for i in range(1,len(p)-1)))/2)

Submission status: Runtime Error

Solution code:
import sys
s=0
p=[list(map(float,e.split(',')))for e in sys.stdin]
n=len(p)
for i in range(n):a,b=p[i];c,d=p[-~i%n];s+=a*d-b*c
print(s/2)

/////////////

Submission status: Runtime Error

Solution code:
import sys
s=0
p=[list(map(float,e.split(',')))for e in sys.stdin]
n=len(p)
for i in range(n):a,b=p[i];c,d=p[-~i%n];s+=a*d-b*c
print(s/2)

//      abs abs

Submission status: Runtime Error

Solution code:
import math

def triangleArea(x1,y1,x2,y2,x3,y3):
	a = math.sqrt(((x1 - x2)**2 + (y1 - y2)**2))
	b = math.sqrt(((x2 - x3)**2 + (y2 - y3)**2))
	c = math.sqrt(((x3 - x1)**2 + (y3 - y1)**2))
	z = (a + b + c) / 2
	S = math.sqrt(z * (z - a) * (z - b) * (z - c))
	return S

apex = []
while True:
	try:
		apex.append(map(float, raw_input().split(',')))
	except:
		S = 0.0
		while len(apex) >= 3:
			for i in range(1,len(apex),2):
				S += triangleArea(apex[i-1][0],apex[i-1][1],apex[i][0],apex[i][1],apex[i+1][0],apex[i+1][1])
			for j in range(1,len(apex),2):
				apex.pop(j)
		print '%.6f' % S
		break