"Hihocoder" 1237:farthest Point Microsoft 2016 school recruit online Pen questions

Source: Internet
Author: User

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

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.