Created
February 20, 2014 18:16
-
-
Save jhtan/9119938 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <iostream> | |
#include <cmath> | |
#include <vector> | |
#include <algorithm> | |
using namespace std; | |
double dist(double x1, double y1, double x2, double y2) { | |
return sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)); | |
} | |
int main() { | |
int n; | |
scanf("%d", &n); | |
while(n) { | |
double x1, y1, x2, y2, A = 0.0; | |
vector<pair<double, double> > V(n+1); | |
for(int i=0; i<n; i++) | |
cin >> V[i].first >> V[i].second; | |
if(n < 3) { | |
printf("0\n"); | |
scanf("%d", &n); | |
continue; | |
} | |
V[n].first = V[0].first; | |
V[n].second = V[0].second; | |
for(int i=0; i<V.size()-1; i++) { | |
x1 = V[i].first, y1 = V[i].second; | |
x2 = V[i+1].first, y2 = V[i+1].second; | |
A += (x1*y2-x2*y1); | |
} | |
A /= 2.0; | |
if(A<0) A*=(-1); | |
printf("%.0lf\n", A); | |
scanf("%d", &n); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment