Cod sursa(job #1559029)

Utilizator dobrebogdanDobre Bogdan Mihai dobrebogdan Data 29 decembrie 2015 22:13:02
Problema Aria Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.1 kb
#include<cstdio>
#include<algorithm>
#include<cmath>
#define eps 1.e-12
using namespace std;
struct sp
{
    long double x,y;
} ve[100005];
long double ccw(sp a,sp b,sp c)
{
    return (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);
}
bool cmp(sp b,sp c)
{
    if(ccw(ve[1],b,c)>=eps)
        return 1;
    return 0;
}
long double dist(sp p1,sp p2)
{
    return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
}
long double arie(sp p1,sp p2,sp p3)
{
    long double a,b,c,p;
    a=dist(p1,p2);
    b=dist(p2,p3);
    c=dist(p1,p3);
    p=(a+b+c)/2;
    return sqrt(p)*sqrt(p-a)*sqrt(p-b)*sqrt(p-c);
}
int main()
{
    freopen("aria.in","r",stdin);
    freopen("aria.out","w",stdout);
    int n,i,j;
    long double sum=0,xp=0,yp=0;
    double s2,x,y;
//punctul e originea:
    scanf("%d",&n);
    for(i=1; i<=n; i++)
    {
        scanf("%lf%lf",&x,&y);
        ve[i].x=x;
        ve[i].y=y;
    }
    n++;
    ve[n]=ve[1];
    for(i=1; i<n; i++)
    {
        sum += (ve[i].x*ve[i+1].y-ve[i+1].x*ve[i].y);
    }
    s2=sum/2;
    printf("%.5lf\n",s2);
    return 0;
}