1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| #include <bits/stdc++.h> #define int long long #define double long double #define pii pair<int, int> #define N 1005 #define x first #define y second #define IOS ios::sync_with_stdio(0),cin.tie(0) using namespace std; int n;
struct pt{ int x,y; bool operator == (pt b){ if(x == b.x && y == b.y)return true; return false; } pt operator - (pt b){return {x - b.x , y - b.y};} pt operator + (pt b){return {x + b.x , y + b.y};} int operator ^ (pt b){return (x * b.y - y * b.x);} int operator * (pt b){return (x * b.x + y * b.y);} }pot[N];
int solve(){ int ans = 0; for(int i=0;i<n;i++)ans += (pot[i] ^ pot[i+1]); return ans; }
signed main(){ IOS; cin>>n; for(int i=0;i<n;i++)cin>>pot[i].x>>pot[i].y; pot[n] = pot[0]; cout<<abs(solve())<<"\n"; }
|