1299 Convex Polygon Area

Source: Internet
Author: User
Description

Returns the coordinates of each point of a convex polygon for its area.

Input

Multiple Input groups. The first positive integer t represents the number of groups.

A positive integer N (1 ≤ n ≤ 1000) In the first line of each group indicates the number of vertices in the polygon,

In the next n + 1 line, each line has two integers, indicating the coordinates x and y of the polygon vertex. These polygon vertices are given in a counterclockwise order.

The line I (0 <I <n + 1) indicates the XI and Yi coordinates of the vertex I (within the int32 range ),

Line n + 1 is the coordinate of the first vertex. (Indicating the first and end of a polygon)

Output

Each group outputs a line with the area of the convex polygon, which retains a decimal number.

Sample Input
130 02 02 20 0
Sample output
2.0

 

 

Mathematical questions

# Include <iostream> # include <cmath> # include <iomanip> using namespace STD; int main () {int t; CIN> T; For (INT I = 0; I <t; I ++) {int N; CIN> N; double Total = 0; int * x = new int [n + 1]; int * Y = new int [n + 1]; for (Int J = 0; j <= N; j ++) {CIN> X [J]> Y [J];} int A [3], B [3], j = 0; double length [3]; int C; A [0] = x [0]; B [0] = Y [0]; do {for (C = 1; C <3; C ++) {A [c] = x [J + C]; B [c] = Y [J + C];} For (C = 0; C <3; C ++) {length [c] = SQRT (A [c]-A [(C + 1) % 3]) * (a [c]-A [(C + 1) % 3]) + (B [c]-B [(C + 1) % 3]) * (B [c]-B [(C + 1) % 3]);} Double P = length [0] + length [1] + length [2]; P/= 2; double S = 1; for (C = 0; C <3; C ++) {S * = p-length [c];} s = SQRT (S * P); Total + = s; j ++;} while (j <n-1); cout <setprecision (1) <fixed <total <Endl;} return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.