1018 - 計算幾何之多邊形面積 - 改革春風吹滿地 (HDU 2036)
阿新 • • 發佈:2018-11-10
分析
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; }