Poj 1981 circle and points (Unit Circle covers n ^ 3 & n ^ 2lgn)

Source: Internet
Author: User

Reprinted please indicate the source, thank youHttp://blog.csdn.net/acm_cxlove/article/details/7854526
By --- cxlove

Question: There is a point set that asks how many points a unit circle can cover.

Http://poj.org/problem? Id = 1981

N ^ 3. A circle with the most vertices must have at least two points on the circle. Of course n> = 2 and the result is greater than 2

In this case, enumerate the two points, find the Unit Circle of the two points, then judge how many points are in the circle, enumerate n ^ 2, and Judge N, which is n ^ 3 in total.

In poj, myCode4.7s Insurance

# Include <iostream> # include <fstream> # include <iomanip> # include <cstdio> # include <cstring> # include <algorithm> # include <cstdlib> # include <cmath> # include <set> # include <map> # include <queue> # include <stack> # include <string> # include <vector> # include <sstream> # include <ctime> # include <cassert> # define ll long # define EPS 1e-8 # define INF 999999.0 # define zero () ABS (a) <EPS # define N 20 # define mod 100000007 # define PI AC OS (-1.0) using namespace STD; struct point {Double X, Y; point () {} Point (double Tx, double ty) {x = TX; y = ty ;}} P [300]; int N; double dist (point P1, point P2) {return SQRT (p1.x-p2.x) * (p1.x-p2.x) + (p1.y-p2.y) * (p1.y-p2.y);} Point get_circle (point P1, point P2) {point mid = point (p1.x + p2.x)/2, (p1.y + p2.y)/2); double angle = atan2 (p1.x-p2.x, p2.y-p1.y); double D = SQRT (1-dist (P1, mid) * dist (P1, mid); Return Point (MID. X + D * C OS (angle), mid. Y + D * sin (angle);} int main () {While (scanf ("% d", & N )! = EOF & N) {for (INT I = 0; I <n; I ++) scanf ("% lf", & P [I]. x, & P [I]. y); int ans = 1; for (INT I = 0; I <n; I ++) {for (Int J = I + 1; j <N; j ++) {If (Dist (P [I], p [J])> 2.0) continue; point central = get_circle (P [I], p [J]); int CNT = 0; // printf ("%. 6f %. 6f \ n ", dist (P [I], Central), dist (P [J], central); For (int K = 0; k <N; k ++) if (Dist (Central, P [k]) <1.0 + EPS) CNT ++; ans = max (ANS, CNT );}} printf ("% d \ n", ANS);} return 0 ;}

N ^ 2lgn practices. If each point is expanded into a unit circle, there may be an intersection between the two to form an intersection arc.

Here, you only need to determine how many times the arc is overwritten. If the arc is covered, the original point must be covered by the center of the arc point.

The practice is a bit strange. N ^ 2 enumeration, find the intersection, save the direction and the polar angle, then sort and scan it again, not very understandable.

To be improved

# Include <iostream> # include <fstream> # include <iomanip> # include <cstdio> # include <cstring> # include <algorithm> # include <cstdlib> # include <cmath> # include <set> # include <map> # include <queue> # include <stack> # include <string> # include <vector> # include <sstream> # include <ctime> # include <cassert> # define ll long # define EPS 1e-8 # define INF 999999.0 # define zero () ABS (a) <EPS # define N 20 # define mod 100000007 # define PI AC OS (-1.0) using namespace STD; struct point {Double X, Y; point () {} Point (double Tx, double ty) {x = TX; y = ty ;}} P [300]; struct node {double angle; bool in;} arc [180000]; int N, CNT; double dist (point P1, point P2) {return SQRT (p1.x-p2.x) * (p1.x-p2.x) + (p1.y-p2.y) * (p1.y-p2.y);} bool CMP (node N1, node N2) {return n1.angle! = N2.angle? N1.angle <n2.angle: n1.in> n2.in;} void maxcirclecover () {int ans = 1; for (INT I = 0; I <n; I ++) {int CNT = 0; for (Int J = 0; j <n; j ++) {if (I = J) continue; If (Dist (P [I], p [J])> (2.0) continue; double angle = atan2 (P [I]. y-P [J]. y, P [I]. x-P [J]. x); double Phi = ACOs (Dist (P [I], p [J])/2); ARC [CNT]. angle = angle-phi; ARC [CNT ++]. in = true; ARC [CNT]. angle = angle + Phi; ARC [CNT ++]. in = false;} Sort (ARC, arc + CNT, CMP); int TMP = 1; for (INT I = 0; I <CN T; I ++) {If (ARC [I]. in) TMP ++; else TMP --; ans = max (ANS, TMP) ;}} printf ("% d \ n", ANS);} int main () {While (scanf ("% d", & N )! = EOF & N) {for (INT I = 0; I <n; I ++) scanf ("% lf", & P [I]. x, & P [I]. y); maxcirclecover ();} return 0 ;}




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.