传送门
解析:
这道题怎么这么扯啊,数据范围都不给 (据说开10000的数组能过)
裸的多边形求面积。
思路:
把原来的多边形面积看成由一个个小三角形的有向面积组成。
直接求出所有小三角形的有向面积之和取绝对值就行了啊。
代码:
#include<iostream>
#include<cstdio>
#include<cctype>
#include<vector>
#include<cmath>
using namespace std;
#define ll long long
#define re register
#define gc getchar
#define pc putchar
#define cs const
inline int getint(){
re int num;
re char c;
while(!isdigit(c=gc()));num=c^48;
while(isdigit(c=gc()))num=(num<<1)+(num<<3)+(c^48);
return num;
}
inline double getdb(){
re double x,y=1.0;
re char c;
re bool f=0;
while(!isdigit(c=gc()))if(c=='-')f=1;x=c^48;
while(isdigit(c=gc()))x=(x*10)+(c^48);
if(c!='.')return f?-x:x;
while(isdigit(c=gc()))x+=(y/=10)*(c^48);
return f?-x:x;
}
struct Point{
double x,y;
Point(cs double &_x=0,cs double &_y=0):x(_x),y(_y){}
friend Point operator+(cs Point &a,cs Point &b){return Point(a.x+b.x,a.y+b.y);}
friend Point operator-(cs Point &a,cs Point &b){return Point(a.x-b.x,a.y-b.y);}
friend double operator*(cs Point &a,cs Point &b){return a.x*b.y-b.x*a.y;}
};
vector<Point> vec;
inline double getarea(){
double res=0;
for(int re i=1;i+1<vec.size();++i)res+=(vec[i]-vec[0])*(vec[i+1]-vec[0]);
return fabs(res)/2;
}
int n;
signed main(){
while((n=getint())!=0){
vec.clear();
for(int re i=1;i<=n;++i)vec.push_back(Point(getdb(),getdb()));
printf("%.0f\n",getarea());
}
return 0;
}