[ create a new paste ] login | about

Link: http://codepad.org/WBmoELb5    [ raw code | fork ]

C++, pasted on Apr 25:
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;

const int MAX_N = 12;

struct Point {
	double x;
	double y;
} point[MAX_N];

double cross(Point o,Point a,Point b) {
	return (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
}

double dis(Point a,Point b) {
	return sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
}

double get_area(Point a,Point b,Point c) {
	double p = dis(a,b);
	double q = dis(b,c);
	double r = dis(a,c);
	double s = (p+q+r)/2;
	return sqrt(s*(s-p)*(s-q)*(s-r));
}

bool cmp(const Point &p1,const Point &p2) {
	return cross(point[0],p1,p2) < 0.0;
}

int main () {
	int n;
	while (scanf("%d",&n) != EOF) {
		for (int X=0;n>X;X++) {
			double i,j;
			cin >> i >> j;
			point[X].x=i;
			point[X].y=j;
		}
		sort(point+1,point+n,cmp);
		double ans = 0.0;
		for (int x=1;n-1>x;x++) {
			ans+=get_area(point[0],point[x],point[x+1]);
		}
		cout<<fixed<<setprecision(2)<<ans<<endl;
	}
}


Output:
No errors or program output.


Create a new paste based on this one


Comments: