HDU 2036 求任意多边形面积板子题

http://acm.hdu.edu.cn/showproblem.php?pid=2036

 1 //求任意多边形面积 要求逆时针或顺时针输入
 2 #include <bits/stdc++.h>
 3 using namespace std;
 4 typedef long long ll;
 5 const int N=1e5+5;
 6 double x[N],y[N];
 7 double cal(int n){
 8     double res=0;
 9     for(int i=2;i<=n;i++){
10         res+=(x[i]*y[i-1]-y[i]*x[i-1])/2;
11     }
12     res+=(x[1]*y[n]-y[1]*x[n])/2;
13     return abs(res);
14 }
15 int main(){
16     int n;
17     while(~scanf("%d",&n)&&n){
18         for(int i=1;i<=n;i++){
19             scanf("%lf%lf",&x[i],&y[i]);
20         }
21         printf("%.1lf\n",cal(n));
22     }
23 } 

 

posted @ 2019-08-28 14:47  Venux  阅读(260)  评论(0编辑  收藏  举报