Skip to content

Instantly share code, notes, and snippets.

@Mjkim-Programming
Created December 22, 2025 06:45
Show Gist options
  • Select an option

  • Save Mjkim-Programming/0bf41ff3e418525e7515333e193e101d to your computer and use it in GitHub Desktop.

Select an option

Save Mjkim-Programming/0bf41ff3e418525e7515333e193e101d to your computer and use it in GitHub Desktop.
Area of polygon
double area(vector<int>& x, vector<int>& y) {
int N = x.size();
ll mulx = 0LL; ll muly = 0LL;
for(int i = 0; i < N; i++) {
mulx += (ll)x[i] * y[(i+1) % N];
}
for(int i = 0; i < N; i++) {
muly += (ll)x[(i+1) % N] * y[i];
}
return 0.5 * llabs(mulx - muly);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment