HDU 2036 reform Spring Breeze blows Montreal __hdu

Source: Internet
Author: User
The change of the Spring breeze blows everywhere Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 19791 accepted Submission (s): 10118


Problem Description "Reform the spring breeze blows the ground,
not AC okay;
Not really.
There is also a three-acre land.
Thank you! (band play) "

Saying that some students are very good mentality, every day to know the game, this test so simple topic, is also foggy, and, even to a few a limerick.
Well, the teacher's responsibility is to help you solve the problem, since you want to farm, it will be divided you.
This field is located in Cangnan County, Zhejiang province Lingxi Lin Home Shop village, the polygon shape of a piece of land, originally is the Linle, is now ready to give you the Wenzhou. However, anything is not so simple, you must first tell me how much area of the land, if the answer is correct to really get the land.
worry about it. is to let you know, farming is also the need for AC knowledge. Let's practice it later.

Input input data contains multiple test instances, one row for each test instance, and the beginning of each row is an integer n (3<=n<=100) that represents the number of edges of the polygon (and of course the number of vertices), followed by the coordinates of n vertices given in a counter-clockwise order (x1, y1, x2, y2 ... xn, yn), to simplify the problem, all the coordinates here are represented by integers.
All integers in the input data are within a 32-bit integer range, and n=0 represents the end of the data and does not handle it.

Output for each test instance, please export the corresponding polygon area, the result is accurate to a decimal point after.
The output of each instance occupies one row.

Sample Input
3 0 0 1, 0 0 1 4 1 0 0 1-1 0 0-1 0
Sample Output
0.5 2.0


Three Point area formula: s=[(X1-X3) * (y2-y3)-(X2-X3) * (y1-y3)]*0.5 counterclockwise positive, clockwise negative
#include <iostream>
#include < Iomanip>
using namespace std;
Int main ()
{
    int n,a[100],b[100];
    double sum;
    while (cin>>n&&n)
    {
        sum=0;
        for (int i=0;i<n;i++)
            CIN>>A[I]> ;>b[i];
        for (int i=0;i<n-1;i++)
            sum=sum+0.5* (a[i ]*b[i+1]-a[i+1]*b[i]);
        sum=sum+0.5* (a[n-1]*b[0]-a[0]*b[n-1]);
        cout<<fixed<<setprecision (1) <<sum<<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.