Polygon Area
InterviewTime limit2sMemory limit128 MB
Given the ordered vertices of a simple polygon, compute its area using the shoelace formula, rounded to one decimal place.
- Level
Easy3 of 10
- Topics
- Geometry, Math, Implementation
- Solved
- No attempts yet
Problem
A polygon is formed by N vertices on a two-dimensional coordinate plane. The vertices are given in order along the boundary of the polygon. Write a program that computes the area of this polygon.
Input
The first line contains an integer N. (3 ≤ N ≤ 10,000)
Each of the next N lines contains the coordinates x and y of one vertex, given in the order that forms the polygon. All coordinates are integers, and the absolute value of each coordinate does not exceed 100,000.
Output
Print the area of the polygon on one line. The value must be rounded to one digit after the decimal point.