标签:意义 简单的 targe pac ros hdu lan space desc
时限:1000ms
#include <iostream> #include <cmath> #include <stdio.h> using namespace std; const double EPS = 1e-10; const int maxn = 1002; struct Point { double x, y; Point(double x=0, double y=0) :x(x), y(y) {} } P[maxn]; typedef Point Vector; Vector operator + (Vector A,Vector B) {return Point(A.x+B.x,A.y+B.y);} Vector operator - (Vector A,Vector B) {return Point(A.x-B.x,A.y-B.y);} Vector operator * (Vector A,double p) {return Point(A.x*p,A.y*p);} Vector operator / (Vector A,double p) {return Point(A.x/p,A.y/p);} double Cross(Point A,Point B) {return A.x*B.y-A.y*B.x;} double PolygonArea(Point p[], int n) { double area = 0; for (int i = 1; i < n-1; i++) { area += Cross(p[i]-p[0], p[i+1]-p[0]); } return area/2; } int main(int argc, char const *argv[]) { int n; while (scanf("%d", &n), n) { for (int i = 0; i < n; i++) { scanf("%lf%lf", &P[i].x, &P[i].y); } printf("%.1lf\n", PolygonArea(P, n)); } return 0; }
标签:意义 简单的 targe pac ros hdu lan space desc
原文地址:http://www.cnblogs.com/lututu123/p/7257242.html