This problem with n^2 algorithm can pass, the first arbitrary enumeration of two points, and the center of the triangle to calculate the area, this area may be added (n-2) times, but note that if there are 3 points in the same side, then to subtract, so in the enumeration, each time enumerating a point, and then enumeration and the point of the degree of the difference between 180 points For area, this area minus 2 * (j-i + 1) times
Code:
#include <cstdio> #include <cstring> #include <cmath> #include <algorithm>using namespace std; const int N = 505;const Double PI = ACOs ( -1.0), int n;double R, D[n * 2];struct point {double x, y; Point () {}-point (Double x, double y) {this->x = x; This->y = y; }};typedef Point Vector; Vector operator-(vector A, vector B) {return vector (a.x-b.x, a.y-b.y);} Inline double Cross (vector a, vector b) {return a.x * b.y-a.y * b.x;}/Fork Product inline Double Area2 (point A, point B, point C) {return cross (b-a, c-a);} Forward area inline Double is (point A, point B, point C) {return fabs (AREA2 (A, B, C))/2;} Inline point Getp (double D) {double rad = d/180 * PI; Return point (cos (RAD) * R, Sin (RAD) * R);} int main () {while (~scanf ("%d%lf", &n, &r) && n | | r) {for (int i = 0; i < n; i++) scanf ("% LF ", &d[i]); Sort (d, D + N); Double ans = 0; for (int i = 0, i < n; i++) for (iNT J = i + 1; J < N; J + +) ans + = is (point (0, 0), GETP (D[i]), GETP (D[j])) * (n-2); for (int i = 0; i < n; i++) D[i + n] = D[i] + 360; for (int i = 0, i < n; i++) {for (int j = i + 2; d[j]-d[i] <; j + +) {ans = 2 * is (Point (0, 0), GETP (D[i]), GETP (d[j% n])) * (J-i-1); }} printf ("%.0f\n", ans); } return 0;}
UVA 11186-circum Triangle (computational geometry + repulsion)