UVA 11186-circum Triangle (computational geometry + repulsion)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.