Title: Given a circle, want you to find a inside or on the edge of the integer points, so that the point to the origin of the maximum distance, if there are more than the same, output x maximum, and then output y max.
Idea: For a circle, the number of the hour inside the x can be determined. You can find the upper and lower bounds of X. is mix = ceil (x0-r)//Because it is a small value, it is rounded up. Mxx=floor (X0+R)//large value to be rounded down
For Y. We can also use the European stock theorem to determine. Y also has a range. But not all Y are enumerated. Obvious. The value of Y is as far away from the center as possible. So you only need to enumerate the farthest two Y values for each X
#include <cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<algorithm>using namespacestd;#defineINF (0X3F3F3F3F)typedefLong Long intLL; #include<iostream>#include<sstream>#include<vector>#include<Set>#include<map>#include<queue>#include<string>DoubleXo,yo,r;DoubleDistDoubleXX1,DoubleYy1,DoubleXX2,Doubleyy2) { returnsqrt ((xx1-xx2) * (XX1-XX2) + (yy1-yy2) * (yy1-yy2));}DoubleEPS = 1e-7;BOOLBig (DoubleADoubleb) { return(A-B) >EPS;}BOOLSame (DoubleADoubleb) { returnFabs (A-B) <EPS;}voidWork () {intMix = (int) Ceil (xo-R); intMxx = (int) Floor (xo+R); Doublemxdis=-1; intAnsx,ansy; for(inti=mix;i<=mxx;++i) {intyy = (int) Floor ((Yo+sqrt (r*r-(I-XO) * (I-XO))) ; DoubleTDIs =Dist (I,YY,XO,YO); if(Big (Tdis,mxdis)) {Mxdis= TDIs; ANSX = i; Ansy =yy; } Else if(Same (Tdis,mxdis) &&i>ansx) {Mxdis= TDIs; ANSX = i; Ansy =yy; } Else if(Same (Tdis,mxdis) &&i==ansx&&yy>=Ansy) {Mxdis= TDIs; ANSX = i; Ansy =yy; } yy= (int) Ceil (Yo-sqrt (r*r-(I-XO) * (I-XO)); TDIs=Dist (I,YY,XO,YO); if(Big (Tdis,mxdis)) {Mxdis= TDIs; ANSX = i; Ansy =yy; } Else if(Same (Tdis,mxdis) &&i>ansx) {Mxdis= TDIs; ANSX = i; Ansy =yy; } Else if(Same (Tdis,mxdis) &&i==ansx&&yy>=Ansy) {Mxdis= TDIs; ANSX = i; Ansy =yy; }} printf ("%d%d\n", Ansx,ansy); return ;}intMain () {#ifdef local freopen ("Data.txt","R", stdin);#endif while(~SCANF ("%LF%LF%LF",&xo,&yo,&R)) work (); return 0;}
View Code
Hihocoder 1237:farthest Point Microsoft 2016 School recruit online pen question