! HDU 4173 to the point distance of not more than 2.5, find the maximum number of points can be satisfied-simple geometry

Source: Internet
Author: User

Test instructions: There are n individuals to the party, but the condition is that the party location to his home is not more than 2.5, now you need to find the best party location for the most people to party.

Analysis:

The topic looks very difficult, how to ask scope and then contain points? In fact, a center + RADIUS does not represent a circle.

Enumerates the center of a circle with a radius of 2.5 for two points, saves it, and then uses these centers to find the distance of all points to the center of the circle, recording the number of points less than or equal to 2.5, and updating the results. 200*199/2*200 does not time out, computing is the basic math knowledge of high school. Be careful with your patience. Note that the calculated floating-point number is determined using EPS.

Code:

#include <iostream> #include <cmath> #include <algorithm> #define EPS 1e-8using namespace Std;int N,ans , cnt;double x[300],y[300];struct node{double x, y;} center[40000];d ouble dis (double a,double b,double c,double d) {return sqrt ((a-c) * (a-c) + (b-d) * (b-d));} void Getcenter (int i,int j) {Double midx= (x[i]+x[j])/2.0;double midy= (Y[i]+y[j])/2.0;double k,b;if (x[i]-x[j]==0) { Double X1=sqrt (6.25-(Midy-y[i]) * (Midy-y[i]) +x[i];d ouble x2=x[i]-sqrt (6.25-(midy-y[i)) * (Midy-y[i]); center[cnt]. X=x1,center[cnt++].y=midy;center[cnt].x=x2,center[cnt++].y=midy;} else if (y[i]-y[j]==0) {double y1=sqrt (6.25-(Midx-x[i]) * (Midx-x[i])) +y[i];d ouble y2=y[i]-sqrt (6.25-(midx-x[i)) * ( Midx-x[i]); center[cnt].x=midx,center[cnt++].y=y1;center[cnt].x=midx,center[cnt++].y=y2;}    Else{double k1= (Y[i]-y[j])/(X[i]-x[j]); k=-1.0/k1; B=midy-k*midx;double tmp1= (x[i]+k*y[i]-k*b);d ouble tmp2= (x[i]+k*y[i]-k*b) * (x[i]+k*y[i]-k*b)-(k*k+1) * (x[i]*x[i]+y [i]*y[i]+b*b-2*b*y[i]-6.25];d ouble x1= (tmp1+sqrt (TMP2))/(k*k+1);d ouble x2= (tmp1-sqRT (TMP2))/(k*k+1);d ouble y1=k*x1+b;double y2=k*x2+b;center[cnt].x=x1,center[cnt++].y=y1;center[cnt].x=x2,center[ Cnt++].y=y2;}}     int main () {while (cin>>n) {Cnt=0,ans=1;     for (int i=0;i<n;i++) cin>>x[i]>>y[i];     for (int i=0;i<n;i++) {for (int j=i+1;j<n;j++) {if (DIS (x[i],y[i],x[j],y[j]) <5.0+eps) getcenter (I,J);     }} for (int i=0;i<cnt;i++) {int tot=0;     for (int j=0;j<n;j++) {if (DIS (x[j],y[j],center[i].x,center[i].y) <2.5+eps) tot++;     } ans=max (Ans,tot);     } cout<<ans<<endl; }}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

! HDU 4173 to the point distance of not more than 2.5, find the maximum number of points can be satisfied-simple geometry

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.