题解:

求多边形面积

分成很多块三角形求就可以了

凹的也是支持的

代码:

#include <bits/stdc++.h>
using namespace std;
#define rint register int
#define IL inline
#define rep(i,h,t) for (int i=h;i<=t;i++)
#define dep(i,t,h) for (int i=t;i>=h;i--)
const double eps=1e-;
struct Point
{
double x,y;
Point(double x1,double y1) {x=x1,y=y1;}
Point(){};
Point operator +(const Point b) const
{
return Point(x+b.x,y+b.y);
}
Point operator -(const Point b) const
{
return Point(x-b.x,y-b.y);
}
double operator *(const Point b) const
{
return x*b.x+y*b.y;
}
double operator ^(const Point b) const
{
return x*b.y-y*b.x;
}
Point operator *(double k)
{
return Point(x*k,y*k);
}
Point operator /(double k)
{
return Point(x/k,y/k);
}
bool operator ==(Point b)
{
return b.x==x&&b.y==y?:;
}
};
struct Line
{
Point x,y;
Line() {};
Line(Point x1,Point y1){x=x1,y=y1;};
};
double lenth(Point x)
{
return sqrt(x.x*x.x+x.y*x.y);
}
double angle(Point x,Point y)
{
return acos(x*y/lenth(x)/lenth(y));
}
int dcmp(double x)
{
if (x<-eps) return(-);
else if (x>eps) return();
else return();
}
Point rotate(Point x,double r)
{
return Point(x.x*cos(r)-x.y*sin(r),x.x*sin(r)+x.y*cos(r));
}
Point gtp(Line x,Line y)
{
Point v1=x.y-x.x; Point v2=y.y-y.x;
double k=((x.x^v1)-(y.x^v1))/(v2^v1);
return y.x+v2*k;
}
double distance(Point x,Line y)
{
Point p1=x-y.x,p2=y.y-y.x;
return fabs((p1^p2)/lenth(p2));
}
const int N=;
Point p[N];
int main()
{
freopen("1.in","r",stdin);
freopen("1.out","w",stdout);
ios::sync_with_stdio(false);
int n;
while (cin>>n&&n)
{
rep(i,,n)
{
int x,y;
cin>>x>>y;
p[i]=Point(x,y);
}
double ans=;
rep(i,,n-)
ans+=(p[i]-p[])^(p[i+]-p[]);
ans/=;
printf("%.1lf\n",ans);
}
return ;
}
04-27 22:39