Simple geometry (circle and Polygon public area) uvalive 7072 Signal Interference (14 Guangzhou D)

Source: Internet
Author: User
Tags scalar

Topic Portal

Test instructions: A polygon, a point and a B point, meet the PB <= K * PA p range and the polygon's public area.

Analysis: This is a Apollonius circle. Since it is a circle, then the general equation of the Circle: (x + d/2) ^ 2 + (y + e/2) ^ 2 = (D ^ 2 + E ^ 2-4 * F)/4, the center and radius are solved by the PB = = PA * k solution equation. Then is a set of templates, Shanghai Jiaotong University's Red Book.

/************************************************* author:running_time* Created TIME:2015/11/9 Monday 11:51:27* Fil E Name:D. cpp ************************************************/#include <bits/stdc++.h>using namespace std;# Define Lson L, Mid, RT << 1#define Rson mid + 1, R, RT << 1 | 1typedef long ll;const int N = 5e2 + 10;const int INF = 0x3f3f3f3f;const int MOD = 1e9 + 7;const Double EPS = 1e-10;c    Onst Double PI = ACOs ( -1.0), int dcmp (double x) {if (Fabs (x) < EPS) return 0; else return x < 0? -1:1;}    struct point {double x, y; Point () {}-point (Double x, double y): X (x), Y (y) {}-operator + (const point &r) const {//vector    addition return point (x + r.x, y + r.y);    } Point operator-(const point &r) const {return point (x-r.x, Y-R.Y);    } Point operator * (double p) const {//vector multiplied by a scalar return point (x * p, Y * p);    } point operator/(double p) Const {   The vector is divided by a scalar return point (x/p, y/p); } BOOL operator < (const point &r) const {return x < r.x | |    (x = = r.x && y < r.y);    } bool operator = = (Const point &r) const {return dcmp (x-r.x) = = 0 && dcmp (y-r.y) = = 0; }};typedef Point Vector;    Point Read_point (void) {double x, y;    scanf ("%lf%lf", &x, &y); Return point (x, y);} Double Polar_angle (Vector V) {return atan2 (v.y, v.x);} Double Dot (point A, point B) {return a.x * b.x + a.y * B.Y;} Double Cross (Point A, point B) {return a.x * b.y-a.y * b.x;} Double Length (Vector v) {return sqrt (dot (v, v));} Double my_sqrt (double x) {return sqrt (max (0.0, x));} Point Ps[n];d ouble R, k;double x1, y1, x2, Y2;int n;double Sqr (double x) {return x * x;}    struct line {point P;    Vector v;    Double R;    Line () {} line (const point &p, const Vector &v): P (P), V (v) {r = Polar_angle (v); } PoiNT point (Double A) {return P + v * A;    }};struct Circle {point C;    Double R; Circle () {} circle (point C, Double R): C (c), R (r) {}-point-point (double a) {return-point (c.x + cos (    A) * R, C.y + sin (a) * R); }};int Line_cir_inter (line L, Circle C, double &t1, double &t2, vector<point> &p) {Double A = L.V    . x, B = l.p.x-c.c.x, C = l.v.y, d = l.p.y-c.c.y;    Double E = A * a + c * C, F = 2 * (A * b + c * d), G = b * B + d * D-C.R * C.R;    Double delta = f * f-4 * e * g;    if (dcmp (delta) < 0) return 0; if (dcmp (delta) = = 0) {T1 = t2 =-F/(2 * e);        P.push_back (L.point (t1));    return 1;    } T1 = (-f-sqrt (delta))/(2 * e);    T2 = (-f + sqrt (delta))/(2 * e);    if (T1 > T2) swap (t1, T2);    if (dcmp (T1) > 0 && dcmp (t1-1) < 0) P.push_back (l.point (t1));    if (dcmp (T2) > 0 && dcmp (t2-1) < 0) P.push_back (l.point (T2)); return (int) P.size ();}    Double Sector_area (Point A, point B) {Double theta = Polar_angle (a)-polar_angle (b);    while (dcmp (theta) <= 0) Theta + = 2 * PI;    while (Theta > 2 * pi) theta-= 2 * PI;    theta = min (theta, 2 * pi-theta); Return R * R * THETA/2;}    Double Cal (Point A, point B) {double T1, T2;    BOOL ina = dcmp (Length (a)-R) < 0;    BOOL INB = dcmp (length (b)-R) < 0;    if (Ina && inb) return Fabs (Cross (A, B))/2.0;    Vector<point> p;    int num = Line_cir_inter (line (A, b-a), Circle (point (0, 0), R), T1, T2, p);    if (INA) return Sector_area (b, p[0]) + fabs (cross (A, p[0]))/2.0;    if (INB) return Sector_area (P[0], a) + Fabs (cross (p[0], B))/2.0;    if (num = = 2) return Sector_area (A, p[0]) + Sector_area (p[1], b) + fabs (cross (p[0], p[1])/2.0; Return Sector_area (A, b);}    Double Cir_poly_area () {double ret = 0;  for (int i=0; i<n; ++i) {int sgn = dcmp (Cross (Ps[i], ps[i+1]));      if (sgn! = 0) {ret = SGN * CALs * CAL (Ps[i], ps[i+1]); }} return ret;}    void init (void) {Double D = (2 * x2-2 * SQR (k) * x1)/(1-SQR (k));    Double E = (2 * y2-2 * SQR (k) * y1)/(1-SQR (k));    Double F = (Sqr (k*x1) +sqr (k*y1)-sqr (x2)-sqr (y2))/(1-SQR (k));    Double x0 = d/2, y0 = E/2;    R = sqrt (F + SQR (D)/4 + SQR (E)/4);  for (int i=0; i<n; ++i) {ps[i].x-= x0;    PS[I].Y-= y0; } Ps[n] = Ps[0];}    int main (void) {int cas = 0;        while (scanf ("%d%lf", &n, &k) = = 2) {for (int i=0; i<n; ++i) {Ps[i] = Read_point ();        } scanf ("%lf%lf", &x1, &y1);        scanf ("%lf%lf", &x2, &y2);        Init ();    printf ("Case%d:%.10f\n", ++cas, Fabs (Cir_poly_area ()));    }//cout << "time Elapsed:" << 1.0 * Clock ()/clocks_per_sec << "s.\n"; return 0;}

  

Simple geometry (circle and Polygon public area) uvalive 7072 Signal Interference (14 Guangzhou D)

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.