[Maximum point of Unit Circle coverage] poj 1981

Source: Internet
Author: User

Classic ry, where the unit circle covers a maximum of points.

Here we use the O (N ^ 3) algorithm, which indicates that there is O (n ^ 2 * logn), but it won't.

Method: Enumerate any two points and use this as the string to create a new circle. (PS: Do not use the string center as the circle because the circle is not the largest.) Then enumerate all points and obtain the maximum value.

# Include <list> # include <map> # include <set> # include <queue> # include <string> # include <deque> # include <stack> # include <algorithm> # include <iostream> # include <iomanip> # include <cstdio> # include <cmath> # include <cstdlib> # include <limits. h> # include <time. h> # include <string. h> using namespace STD; # define ll long # define PI ACOs (-1.0) # define Max int_max # define min int_min # define EPS 1e-10 # define fre freopen ("a.txt ", "r", stdin) # define mod 1000000007 # define n 305 struct point {Double X, Y;} p [N]; double DIS (point a, point B) {// return (. x-b.x) * (. x-b.x) +. y-b.y) * (. y-b.y);} Point Gao (point a, point B) {point mid, TMP, P0; mid. X = (. X + B. x)/2; mid. y = (. Y + B. y)/2; double S = DIS (MID, a); s = SQRT (1.0-s); TMP. X = (. x-b.x); TMP. y = (. y-b.y); if (. X = B. x) {// The parallel Y axis of the string vertical line must be specially processed when x = mid. x; required y = mid. y-S;} else {double angle = atan (-TMP. x)/tmp. y); bytes X = mid. x-S * Cos (angle); // There are two possible cases here. You only need one of them (take the left or right) and choose y = mid. y-S * sin (angle);} return P0;} int main () {int N; int I, j; while (scanf ("% d", & N) & N) {for (I = 0; I <n; I ++) {scanf ("% lf", & P [I]. x, & P [I]. y);} int ans = 1; // the smallest vertex is for (I = 0; I <n; I ++) {for (j = I + 1; j <n; j ++) {If (DIS (P [I], p [J])> 4.0) continue; // If the square distance between the two circles is greater than 4, the point P0 cannot be intersecting; p0 = Gao (P [I], p [J]); // take the line of the two circles as the string and make the circle, and obtain the center int CNT = 0; For (int K = 0; k <n; k ++) {If (DIS (P0, P [k]) <= 1.00001) // CNT ++;} If (ANS <CNT) ans = CNT ;}} printf ("% d \ n", ANS);} 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.