版权声明:虽然我只是个小蒟蒻但转载也请注明出处哦 https://blog.csdn.net/weixin_42557561/article/details/83145961
分析
sb题
主要是题面太皮,我才去做的:)
简单的多边形面积,用叉积即可
代码
#include<bits/stdc++.h>
#define in read()
#define N 105
using namespace std;
inline int read(){
char ch;int f=1,res=0;
while((ch=getchar())<'0'||ch>'9') if(ch=='-') f=-1;
while(ch>='0'&&ch<='9'){
res=(res<<3)+(res<<1)+ch-'0';
ch=getchar();
}
return f==1?res:-res;
}
struct point{
double x,y;
point(){}
point(double _x,double _y):x(_x),y(_y){}
friend inline point operator +(const point &a,const point &b){return point(a.x+b.x,a.y+b.y);}
friend inline point operator -(const point &a,const point &b){return point(a.x-b.x,a.y-b.y);}
friend inline point operator *(double k,const point &a){return point(a.x*k,a.y*k);}
friend inline double dot(const point &a,const point &b){return a.x*b.x+a.y*b.y;}
friend inline double cross(const point &a,const point &b){return a.x*b.y-a.y*b.x;}
friend inline double len(const point &a){return sqrt(dot(a,a)); }
friend inline double dis(const point &a,const point &b){return len(a-b);}
}a[N];
int n;
int main(){
while(1){
n=in;
if(!n) break;
int i,j,k;
for(i=1;i<=n;++i) a[i].x=in,a[i].y=in;
double ans=0;
a[n+1]=a[1];
for(i=1;i<=n;++i) ans+=cross(a[i],a[i+1]);
printf("%.1lf\n",fabs(ans/2.0));
}
return 0;
}