计算多边形面积

 

例题:https://vjudge.net/problem/Gym-102501F#author=0

 1 #include<iostream>
 2 #include<algorithm>
 3 #include<vector>
 4 #include<cstring>
 5 #include<cstdio>
 6 #include<bits/stdc++.h>
 7 using namespace std;
 8 #define mem(s,n) memset(s,n,sizeof s);
 9 #define PI acos(-1.0)
10 typedef long long ll;
11 const int maxn=1e7+5;
12 const ll Inf=0x7f7f7f7f;
13 const int mod=2e6;
14 int n;
15 struct node
16 {
17     ll x,y;
18 }e[101];
19 int main()
20 {
21     int n;
22     cin>>n;
23     double sum=0;
24     while(n--)
25     {
26         int p;
27         cin>>p;
28         ll ans=0;
29         for(int i=0;i<p;i++)
30         {
31             cin>>e[i].x>>e[i].y;
32         }
33         for(int i=0;i<p;i++)
34         {
35             ans+=e[i].x*(e[(i+1)%p].y)-e[i].y*(e[(i+1)%p].x);
36         }
37         sum+=abs(ans*0.5);
38     }
39     printf("%lld\n",(ll)floor(sum));
40     
41 }

 

posted @ 2020-10-03 10:59  JamZF  阅读(145)  评论(0编辑  收藏  举报