根据多边形的n个点求出多边形的面积
很方便,两两相邻原点向量求差积,处以二即是面积。
#include<iostream> #include<cstring> #include<algorithm> #include<string> #include<cmath> #include<queue> #include<cstdio> using namespace std; const int MAXN=105; int n; int main() { cin>>n; double x0,y0; double x1,y1; double x2,y2; cin>>x1>>y1; x0=x1; y0=y1; double sum=0; for(int i=2;i<=n;i++) { cin>>x2>>y2; sum+=(double)(x1*y2-x2*y1); x1=x2; y1=y2; } x2=x0; y2=y0; sum+=(double)(x1*y2-x2*y1); sum/=2; cout<<sum<<endl; return 0; }