Poj Solution 1385

http://poj.org/problem?id=1385

#include<iostream>
#include"stdio.h"
#include"memory.h"
using namespace std;

double x,y,x1,y1,xb,yb;
double area,x_sum,y_sum,temp;

int main()
{
    int t,n,i;
    cin>>t;
    while(t--)
    {
        cin>>n;
        cin>>x1>>y1;
        
        xb=x1,yb=y1;

        area=x_sum=y_sum=0;
        for(i=1;i<=n;i++)
        {
            if(i<n)cin>>x>>y;
            else x=xb,y=yb;

            temp=x*y1-y*x1;
            x_sum+=temp*(x+x1);
            y_sum+=temp*(y+y1);
            area+=temp;
            x1=x,y1=y;
        }

        printf("%.2lf %.2lfn",(double)((long)(x_sum/area/3*100))/100,(double)(long)(y_sum/area/3*100)/100);
    }
    return 0;
}
											
This entry was posted in poj. Bookmark the permalink.