Multi-deformation area of cross-product

Source: Internet
Author: User

Description

Mr. Tenant is going to buy a new house. In fact, he's going to buy a piece by land and build his new house on it. In order to decide which piece of land to buy, Mr. Tenant needs a program which would give a score to each piece. Each candidate piece's a polygonal shape (not necessarily convex), and Mr. Tenant wonders what's the best score is. Among possible scores, he considered the number of vertices, sum of angles, minimum number of required guards, and so for Th. Finally, Mr Tenant decided, the best score for a piece of land would simply is its area. Your task is to write the desired scoring program.

Input

The input file consists of multiple pieces of land. Each piece are a simple polygon (so is, a polygon which does not intersect itself). A polygon description starts with a positive integer number k, followed by k vertices, where each vertex consists of both C Oordinates (floating-point numbers): X and Y. Naturally, the last vertex was connected by a edge to the first vertex. Note that each polygon can is ordered either clockwise or counterclockwise. The input ends with a "0" (the number zero).

Output

For each piece of land, the output should consist of exactly one line containing the score of that piece, rounded to the N Earest integer number. (halves should is rounded up, but Mr Tenant never faced such cases.)

Sample Input

1   123.45 67.890 3   0.001 0   1.999 0   0 2 5   Ten 12.0 10.0 0

Sample Output

023

Hint

The scoring program have to handle well degenerate cases, such as, polygons with only one or both vertices.
#include<iostream>#include<cmath>#include<stdio.h>UsingNamespace Std;IntMain(){float x0, y0, x1, y1;int n;While(scanf("%d", &n)!=-1){If(n==0)Break;float sum=0;scanf("%f%f", &x0, &y0);float XX=x0Yy=y0; N--;While(n--){scanf("%f%f", &x1, &y1); Sum+=x0*y1-x1*y0; X0=x1; Y0=y1; } x1=xx; y1=yy; sum+=x0*y1-x1 *y0; printf("%.0f\ n",fabs(sum)/2+1e-6); } return 0;}              

Multi-deformation area of cross-product

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.