Bzoj3007: Save the Little Cloud Princess

Source: Internet
Author: User
Tags cmath

Descriptionthe hero is about to embark on the path of saving the Princess ...this time the goal of salvation is-love and justice of the Princess Xiao Yun. the hero came to the door of the boss's cave, he suddenly was ignorant, because in front of not just a boss, but on thousands boss. When the hero realizes he is still level 1, he understands that this is an impossible task. But he did not give up, he was thinking, can avoid the boss to save the princess, hehe. The boss's Cave can be viewed as a rectangle, the hero in the lower-left corner (Row,line), and the princess in the upper-right corner. Heroes in order to avoid bosses, of course, the farther away from the boss, the better, so the hero decided to find a path to the shortest distance from the boss farthest. Ps: The hero walks the direction is arbitrary. can you help him? when the hero found a beautiful princess Xiao Yun, immediately surrounded by the Boss!!! The hero slowly closed his eyes, hand flick, white light after the use of the back of the town scroll, returned to the castle, but only Xiao Yun Princess back ... Because the hero forgot to enter the town of the law. InputThe first line, enter three integers, n indicates the number of bosses, Row,line represents the size of the rectangle;next n rows, two integers per line represent the position coordinates of the boss. Outputoutputs a decimal number that indicates the hero's path is farthest from the boss and is accurate to two digits after the decimal point. The two-part answer R, the circle of radius R for each point, determines whether the circle is cut off (n,m), that is, from the left and the upper boundary can go through the circle to the right/lower boundary
#include <cstdio>#include<cmath>#include<algorithm>intN;DoubleXm,ym;structpos{Doublex, y;} ps[3010];intq[3010],ed[3010];BOOLDISCMP (DoubleXDoubleYDoublez) {    returnx*x+y*y<z*Z;}BOOLChkDoubleR) {    intQl=0, qr=0;  for(intI=0; i<n;i++){        if(ps[i].x-1<r| | Ps[i].y+r>ym) {Q[QR++]=i; Ed[i]=1; if(ps[i].x+r>xm| | ps[i].y-r<1)return 1; }Elseed[i]=0; }     while(ql!=qr) {        intw=q[ql++];  for(intI=0; i<n;i++)if(!ED[I]&AMP;&AMP;DISCMP (ps[i].x-ps[w].x,ps[i].y-ps[w].y,r*2) ) {Q[QR++]=i; Ed[i]=1; if(ps[i].x+r>xm| | ps[i].y-r<1)return 1; }    }    return 0;}intMain () {scanf ("%D%LF%LF",&n,&xm,&ym);  for(intI=0; i<n;i++) {scanf ("%LF%LF",&ps[i].x,&ps[i].y); }    DoubleL=0, r=xm+ym+1;  while(r-l>1e-5){        DoubleM= (L+R)/2.; if(CHK (M)) R=M; ElseL=l; } printf ("%.2lf\n", (L+R)/2.); return 0;}
You can also use the Kruskal of the smallest spanning tree to add edges until the first edge is found to connect the left and top borders to the right and bottom boundaries
#include <cstdio>#include<cmath>#include<algorithm>intn,xm,ym,ep=0;intf[3010];structpos{intx, y;} ps[3010];structedge{intb;Long LongC;} e[10000010];BOOL operator<(Edge A,edge b) {returna.c<B.C;} InlineLong LongMin2 (Long LongALong Longb) {a*=a;b*=b; returnA<b?a:b;}int Get(intx) {    intA=X,c;  while(X!=f[x]) x=F[x];  while(x!= (C=f[a])) f[a]=x,a=C; returnx;}intMain () {scanf ("%d%d%d",&n,&xm,&ym);  for(intI=0; i<n;i++) {F[i]=i; scanf ("%d%d",&ps[i].x,&ps[i].y); E[ep++]= (Edge) {i,n,4*min2 (xm-ps[i].x,ps[i].y-1)}; E[ep++]= (Edge) {i,n+1,4*min2 (ps[i].x-1, ym-ps[i].y)};  for(intj=0; j<i;j++){            Long Longx=ps[i].x-ps[j].x,y=ps[i].y-ps[j].y; E[ep++]= (Edge) {i,j,x*x+y*y}; }} F[n]=n;f[n+1]=n+1; Std::sort (E,e+EP);  for(intI=0; i<ep;i++){                intA=Get(E[I].A), b=Get(E[I].B); if(a!=b) {F[a]=b; if(Get(n) = =Get(n+1) {printf ("%.2f\n", sqrt (E[I].C)/2. +1e-8); return 0; }        }    }    return 0;}

Bzoj3007: Save the Little Cloud Princess

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.