Problem:


Area

For a given polygon g, computes the area of the polygon.

g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of g. The line segment connecting pn and p1 is also a side of the polygon.

Note that the polygon is not necessarily convex.

Input

The input consists of coordinates of the points p1,..., pn in the following format:

n
x1 y1 
x2 y2
:
xn yn

The first integer n is the number of points. The coordinate of a point pi is given by two integers xi and yi. The coordinates of points are given in the order of counter-clockwise visit of them.

Output

Print the area of the polygon in a line. The area should be printed with one digit to the right of the decimal point.

Constraints

3 ≤ n ≤ 100

-10000 ≤ xi, yi ≤ 10000

No point will occur more than once.

Two sides can intersect only at a common endpoint.

Sample Input 1

3
0 0
2 2
-1 1

Sample Output 1

2.0

Sample Input 2

4
0 0
1 1
1 2
0 2

Sample Output 2

1.5



Sample input:
3
0 0
2 2
-1 1


Sample output:
2.0

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

###########################
#          幾何
###########################
def sgn(a):
    if a < -eps: return -1
    if a >  eps: return  1
    return 0

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

    def tolist(self):
        return [self.x,self.y]

    def __add__(self,p):
        return Point(self.x+p.x, self.y+p.y)
    def __iadd__(self,p):
        return self + p

    def __sub__(self,p):
        return Point(self.x - p.x, self.y - p.y)
    def __isub__(self,p):
        return self - p

    def __truediv__(self,n):
        return Point(self.x/n, self.y/n)
    def __itruediv__(self,n):
        return self / n

    def __mul__(self,n):
        return Point(self.x*n, self.y*n)
    def __imul__(self,n):
        return self * n

    def __lt__(self,other):
        tmp = sgn(self.x - other.x)
        if tmp != 0:
            return tmp < 0
        else:
            return sgn(self.y - other.y) < 0

    def __eq__(self,other):
        return sgn(self.x - other.x) == 0 and sgn(self.y - other.y) == 0

    def abs(self):
        return math.sqrt(self.x**2+self.y**2)

    def dot(self,p):
        return self.x * p.x + self.y*p.y

    def det(self,p):
        return self.x * p.y - self.y*p.x

    def arg(self,p):
        return math.atan2(y,x)

# 点の進行方向 a -> b -> c
def iSP(a,b,c):
    tmp = sgn((b-a).det(c-a))
    if tmp > 0:   return 1   # 左に曲がる場合
    elif tmp < 0: return -1  # 右に曲がる場合
    else: # まっすぐ
        if sgn((b-a).dot(c-a)) < 0: return -2 # c-a-b の順
        if sgn((a-b).dot(c-b)) < 0: return  2 # a-b-c の順
        return 0 # a-c-bの順

# ab,cd の直線交差
def isToleranceLine(a,b,c,d):
    if sgn((b-a).det(c-d)) != 0: return 1 # 交差する
    else:
        if sgn((b-a).det(c-a)) != 0: return 0 # 平行
        else: return -1 # 同一直線

# ab,cd の線分交差 重複，端点での交差もTrue
def isToleranceSegline(a,b,c,d):
    return sgn(iSP(a,b,c)*iSP(a,b,d))<=0 and sgn(iSP(c,d,a)*iSP(c,d,b)) <= 0

# 直線ab と 直線cd の交点 (存在する前提)
def Intersection(a,b,c,d):
    tmp1 = (b-a)*((c-a).det(d-c))
    tmp2 = (b-a).det(d-c)
    return a+(tmp1/tmp2)

# 直線ab と 点c の距離
def DistanceLineToPoint(a,b,c):
    return abs(((c-a).det(b-a))/((b-a).abs()))

# 線分ab と 点c の距離
def DistanceSeglineToPoint(a,b,c):
    if sgn((b-a).dot(c-a)) < 0: # <cab が鈍角
        return (c-a).abs()
    if sgn((a-b).dot(c-b)) < 0: # <cba が鈍角
        return (c-b).abs()
    return DistanceLineToPoint(a,b,c)

# 直線ab への 点c からの垂線の足
def Vfoot(a,b,c):
    d = c + Point((b-a).y,-(b-a).x)
    return Intersection(a,b,c,d)

# 多角形の面積
def PolygonArea(Plist):
    #Plist = ConvexHull(Plist)
    L = len(Plist)
    S = 0
    for i in range(L):
        tmpS = (Plist[i-1].det(Plist[i]))/2
        S += tmpS
    return S

# 多角形の重心
def PolygonG(Plist):
    Plist = ConvexHull(Plist)
    L = len(Plist)
    S = 0
    G = Point(0,0)
    for i in range(L):
        tmpS = (Plist[i-1].det(Plist[i]))/2
        S += tmpS
        G += (Plist[i-1]+Plist[i])/3*tmpS
    return G/S

# 凸法
def ConvexHull(Plist):
    Plist.sort()
    L = len(Plist)
    qu = deque([])
    quL = 0
    for p in Plist:
        while quL >= 2 and iSP(qu[quL-2],qu[quL-1],p) == 1:
            qu.pop()
            quL -= 1
        qu.append(p)
        quL += 1

    qd = deque([])
    qdL = 0
    for p in Plist:
        while qdL >= 2 and iSP(qd[qdL-2],qd[qdL-1],p) == -1:
            qd.pop()
            qdL -= 1
        qd.append(p)
        qdL += 1

    qd.pop()
    qu.popleft()
    hidari = list(qd) + list(reversed(qu)) # 左端開始，左回りPlist
    return hidari

N = int(input())
Plyst = [Point(*inpl()) for _ in range(N)]
print(PolygonArea(Plyst))

Submission status: Accepted

Solution code:
n = int(input())
vec = []
for i in range(n):
    vec += [list(map(int, input().split()))]
vec += [vec[0]]
Sum = 0
def cross(a, b):
    return a[0]*b[1]-a[1]*b[0]
for a, b in zip(vec[0:-1],vec[1:]):
    Sum += cross(a,b)/2
print(f'{abs(Sum):.1f}')

Submission status: Accepted

Solution code:
def cross(ux, uy, vx, vy):
    return ux*vy - uy*vx


n = int(input())
points = [tuple(map(int, input().split())) for _ in range(n)]

area = 0
x1, y1 = points[0]
for i in range(1, n - 1):
    xi, yi = points[i]
    xj, yj = points[i + 1]
    area += cross(xi - x1, yi - y1, xj - x1, yj - y1)

print('{:.1f}'.format(area / 2))

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 = []
N = int(input().strip())
for _ in range(N):
    x,y = map(float,input().strip().split())
    P.append(complex(x,y))
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("%.1f" % (abs(total)/2.0))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# CGL_3_A: Polygon - Area


def area(ps):
    p0, p1, *ps = ps
    area = 0.0

    x0, y0 = p0
    x1, y1 = p1
    v1 = (x1-x0, y1-y0)
    for p2 in ps:
        x2, y2 = p2
        v2 = (x2-x0, y2-y0)
        area += cross(v1, v2)
        v1 = v2

    return area / 2


def cross(v0, v1):
    x0, y0 = v0
    x1, y1 = v1
    return x0*y1 - x1*y0


def run():
    n = int(input())
    ps = []
    for _ in range(n):
        x, y = [int(i) for i in input().split()]
        ps.append((x, y))

    print("{:.1f}".format(area(ps)))


def show():
    import matplotlib.pyplot as plt
    n = int(input())
    xs = []
    ys = []
    for _ in range(n):
        x, y = [int(i) for i in input().split()]
        xs.append(x)
        ys.append(y)

    plt.plot(xs, ys)
    plt.show()


if __name__ == '__main__':
    run()

Submission status: Accepted

Solution code:
#!/usr/bin/env python

import sys
import math
import itertools as it
from collections import deque

sys.setrecursionlimit(10000000)

n = input()
ans = 0
x0, y0 = map(int, raw_input().split())
xp, yp = map(int, raw_input().split())
for loop in range(n - 2):
    xq, yq = map(int, raw_input().split())
    ans += (xp - x0) * (yq - y0) - (xq - x0) * (yp - y0)
    xp, yp = xq, yq

print "%.1f" % (float(ans) / 2)

Submission status: Runtime Error

Solution code:
n = int(input())
P =[]
s = 0
for i in range(n):P.append([int(i) for i in input().split()])
P.append(P[0])
for i in range(n):
    a = P[i][0] ; b = P[i][1]; c = P[i+1][0] ; P[i+1][1]
    s += a * d - b * c
print(abs(s)*0.5)

Submission status: Runtime Error

Solution code:
n = int(input())
P =[]
s = 0
x0,y0 = [int(i) for i in input().split()]
for i in range(n):
    x,y = [int(i) for i in input().split()]
    P.append([x-x0,y-y0])
for i in range(n-2):
    s += P[i][0]*P[i+1][1] - P[i][1]*P[i+1][0]
print(abs(s)*0.5)

Submission status: Runtime Error

Solution code:
n = int(input())
P =[]
s = 0
x,y = 
for _ in range(n):P.append([int(i) for i in input().split()])
P.append(P[0])
for j in range(n):s += P[j][0]*P[j+1][1] - P[j][1]*P[j+1][0]
print(s*0.5)

Submission status: Runtime Error

Solution code:
n = int(input())
P =[]
s = 0
for _ in range(n):P.append([int(-i) for i in input().split()])
P.append(P[0])
for j in range(n):s += P[j][1]*P[j+1][0] -  P[j][0] * P[j+1][1]
print(s*0.5)

Submission status: Runtime Error

Solution code:
n = int(input())
x = range(n)
P =[]
s = 0
for _ in x:P += [int(i) for i in input().split()]
P+=P[0]
for j in x:s += P[j][0]*P[j+1][1] - P[j][1]*P[j+1][0]
print(s*0.5)

Submission status: Runtime Error

Solution code:
n = int(input())
x = range(n)
P =[]
s = 0
for _ in x:P += [[int(i) for i in input().split()]]
P+=P[0]
for j in x:s += P[j][0]*P[j+1][1] - P[j][1]*P[j+1][0]
print(s*0.5)

Submission status: Runtime Error

Solution code:
n = int(input())
x = range(n)
P =[]
s = 0
for _ in x:P.append([int(i) for i in input().split()])
P+=P[0]
for j in x:s += P[j][0]*P[j+1][1] - P[j][1]*P[j+1][0]
print(s*0.5)

Submission status: Runtime Error

Solution code:
x=range(int(input()))
P=[]
_=0
for _ in x:P+=[[int(i) for i in input().split()]]
P+=[P[0]]
for j in x:s+=P[j][0]*P[j+1][1]-P[j][1]*P[j+1][0]
print(s*0.5)

Submission status: Runtime Error

Solution code:
x=range(int(input()))
f=lambda a,b,c,d : a*d - b*c 
P=[]
for _ in x:P+=[[int(i) for i in input().split()]]
_=0
P+=[P[0]]
for j in x:_+=f(P[j][0],P[j][1],,P[j+1][0]P[j+1][1])
print(_*0.5)