Source of the topic:
Http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=41
Test instructions: Determines the maximum number of points that can be moved by a semicircle.
Analysis: Calculate the points within the circle, and then enumerate the points, the points and the center of the line of the diameter of the left and right points of the statistics, the maximum can be.
The code is as follows:
Const DoubleEPS = 1e- A;Const intMax_n = the;DoubleAddDoubleADoubleb) { return(Fabs (A + B) < EPS * (Fabs (a) + fabs (b)))?0: (A +b);}structpoint{Doublex, y; Point () {}, point (DoubleXDoubley): x (x), Y (y) {}DoubleDist (point P) {returnsqrt (Add (x-p.x) * (x-p.x), (y-p.y) * (Y-( p.y))); } Pointoperator-(point P) {returnPoint (Add (x,-p.x), add (Y,-p.y)); } Double operator^(point P) {returnAdd (x * p. y,-y *p.x); }}po[max_n]; Point ro;DoubleR;intMain () {intN, I, J, Maxm; while(SCANF ("%LF%LF%LF", &ro.x, &ro.y, &r) && r >0) {MAXM=0 ; scanf ("%d", &N); for(i =0; I < n; i++) scanf ("%LF%LF", &po[i].x,&po[i].y); intL =0 ; for(i =0; i< N; i++) if(Ro.dist (Po[i])-R <=EPS) Po[l++] =Po[i]; N=l; intLeft , right; for(i =0; I < n; i++) { left=0, right =0; for(j =0; j< N; J + +){ DoubleD = (Po[i]-ro) ^ (Po[j]-ro); if(D >0) Left + + ; Else if(D <0) Right + + ; Else{ Left++ ; Right++ ; }} MAXM= Maxm < left?LEFT:MAXM; MAXM= Maxm < right?RIGHT:MAXM; } printf ("%d\n", MAXM); } return 0;}