Calculation of the area of any polygon # include <iostream> #include <cmath> #include <iomanip>using namespace std;typedef std:: Pair<double,double> Point, #pragma warning (disable:4244) Double det (point p0,point p1,point p2) {return ( P1.first-p0.first) * (P2.second-p0.second)-(P1.second-p0.second) * (P2.first-p0.first);} Double Ploygon_area (int n,point p[]) {double S=0.0f;int i=1;for (; i < n-1;i++) s + = det (p[0],p[i],p[i+1]); return 0.5*fabs (s);} int main () {int i,n;double s;point p_xy[101];while (cin >> n && n! = 0) {for (i=0; i<n; i++) {//cout<<en dl<< "points[" <<i<< "]="; cin>>p_xy[i].first>>p_xy[i].second;} S=ploygon_area (n, p_xy); cout << setiosflags (ios::fixed); cout.precision (1); cout << s << std::endl;} return 0;}
http://blog.csdn.net/hemmingway/article/details/7814494----> To understand the principle, see here.
Hangzhou Electric OJ--2036 reform spring breeze blowing everywhere