Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
718 B
1
Indexable
Never
#include <iostream>
#include<iomanip>
#include<cmath>

using namespace std;

int main()
{
    int n;
    cin >> n;
    double c[50000][2];
    double sum1;
    double sum2;
    double s;
    sum1 = 0;
    sum2 = 0;
    s = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> c[i][0];
        cin >> c[i][1];
    }
    for ( int i = 0; i < n; i++)
    {
        sum1 = sum1 + c[i][0] * c[i+1][1];
        sum2 = sum2 + c[i][1] * c[i+1][0];
    }
    s = (sum1 + (c[n][0] * c[0][1])) - (sum2 + (c[n][1] * c[0][0]));
    if (s < 0)
    {
        cout.precision(3);
        cout << fixed;
        cout << s / 2 * -1;
    }
    else
    {
        cout.precision(3);
        cout << fixed;
        cout << s / 2;
    }
}
Leave a Comment