Problem:
Area For a given polygon g , computes the area of the polygon.  g is represented by a sequence of points p 1 , p 2 ,..., p n where line segments connecting p i and p i+1 (1 ≤ i ≤ n-1 ) are sides of g . The line segment connecting p n and p 1 is also a side of the polygon. Note that the polygon is not necessarily convex. Input The input consists of coordinates of the points p 1 ,..., p n in the following format:  n  x 1  y 1  x 2  y 2 : x n  y n  The first integer n is the number of points. The coordinate of a point p i is given by two integers x i and y i . 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 ≤ x i , y i ≤ 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

Solution (Python):




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()

Solution (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)