【題解】CSES 2191 Polygon Area

【題目敘述】https://cses.fi/problemset/task/2191/

;
long long ans;
 
struct Point{
    long long x, y;
    Point operator-(Point b){
        return {x-b.x, y-b.y};
    }
}a[1005];
 
long long cross(Point a, Point b){
    return a.x*b.y - a.y*b.x;
}
 
int main() {
    cin >> n;
    cin >> a[0].x >> a[0].y;
    for (int i = 1; i < n; i++){
        cin >> a[i].x >> a[i].y;
        ans += cross(a[i-1], a[i]);
    }
    ans += cross(a[n-1], a[0]);
    cout << abs(ans) << "\n";
}
分享本文 Share with friends