UVa 10005-packing Polygons

Source: Internet
Author: User

Title: give you a polygon that asks if you can include a circle with a radius of R.

Analysis: Calculate geometry, minimum circle coverage. Bare minimum circle inclusions, using a random incremental algorithm.

Description: Finally thanks for the first minimum dollar cover ╮(╯▽╰)╭.

#include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include < Cstdio> #include <cmath>using namespace std;typedef struct pnode{double x,y,r;pnode () {}pnode (double x, double y , double R) {x = X;y = Y;r = R;} Pnode (Pnode A, Pnode b) {x = (a.x+b.x)/2;y = (a.y+b.y)/2;r = sqrt ((a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (A.Y-B.Y))/2;}} Point;point p[101];d ouble dist_p2p (Point A, point B) {return sqrt ((a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (A.Y-B.Y));} Triangle Circumcenter Point Circle (Point A, point B, point P) {Double A1 = a.x-b.x, B1 = a.y-b.y, C1 = (A.X*A.X-B.X*B.X+A.Y*A.Y-B.Y*B.Y)/ 2;double A2 = p.x-b.x, B2 = p.y-b.y, C2 = (p.x*p.x-b.x*b.x+p.y*p.y-b.y*b.y)/2;point c;c.x = (C1*B2-C2*B1)/(A1*B2-A2*B1); c. y = (A1*C2-A2*C1)/(A1*B2-A2*B1); C.R = dist_p2p (c, a); return C;} Point Smallest_enclosing_circle (Point p[], int n) {random_shuffle (P, p+n);p oint c = Point (P[0], p[1]); for (int i = 2; I &lt ; N + + i) if (dist_p2p (P[i], C) > c.r+1e-6) {//smallest_enclosing_circle_2point c = poinT (P[0], p[i]); for (int j = 1; j < I; + + j) if (dist_p2p (P[j], C) > c.r+1e-6) {c = point (P[j], p[i]); for (int k = 0; k < J; + + K) if (dist_p2p (P[k], C) > c.r+1e-6) c = Circle (P[i], p[j], p[k]);}} return c;} int main () {int n;double r;while (~scanf ("%d", &n) && N) {for (int i = 0; i < n; + + i) scanf ("%lf%lf", &p[i ].X,&AMP;P[I].Y); scanf ("%lf", &r);p oint c = smallest_enclosing_circle (P, n); if (C.R < r+1e-6) printf ("The Polygon  Can be packed in the circle.\n ");    elseprintf ("There is no" by packing that polygon.\n ");} return 0;}


UVa 10005-packing Polygons

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.