Test instructions: Give a 1000*1000 size matrix, there are a number of circles, indicating obstacles, now to find a path from the left to the right, the output entrance and exit coordinates, if there are many answers, output y value the largest answer.
Analysis: Starting with the circle connected to the DFS, each to find the intersection with the DFS path, if you can access to the following, then the left and right is definitely not connected; and update the maximum Y-value answer at DFS.
See the code for details:
1#include <stdio.h>2#include <algorithm>3#include <string.h>4#include <Set>5#include <math.h>6 using namespacestd;7 Const intN = ++5;8 Const intINF =2e9;9typedefLong Longll;Tentypedef pair<int,int>PII; One A intN; - intVis[n]; - structCircle the { - intX,y,r; - voidRead () - { +scanf"%d%d%d",&x,&y,&R); - } + }c[n]; A at BOOLCan (Circle A,circle b) - { - DoubleDX = a.x-b.x; - DoubleDY = a.y-b.y; - DoubleD = sqrt (dx*dx+dy*dy); - returnD <= A.R +B.R; in } - to DoubleAnsl =0, AnsR =0; + voidUpdateintu) - { the if(c[u].x <=C[U].R) * { $ Doublet = sqrt (c[u].r*c[u].r-c[u].x*c[u].x);Panax Notoginseng Doublepos = c[u].y-T; -Ansl =min (Ansl, POS); the } + if(c[u].x + C[U].R >= +) A { the Doublett =1000.0-c[u].x; + Doublet = sqrt (c[u].r*c[u].r-tt*TT); - Doublepos = c[u].y-T; $AnsR =min (AnsR, POS); $ } - } - the BOOLDfsintu) - {WuyiVis[u] =1; the if(C[u].y <= C[U].R)return false; - update (u); Wu for(intI=1; i<=n;i++) - { About if(!vis[i] &&can (C[u], c[i])) $ { - if(!dfs (i))return false; - } - } A return true; + } the - voidSolve () $ { theAnsl = +, AnsR = +; thememset (Vis,0,sizeof(Vis)); the for(intI=1; i<=n;i++) the { - if(!vis[i] && c[i].y + C[I].R >= +) in { the if(!DFS (i)) the { AboutPuts"Impossible"); the return ; the } the } + } -printf"0.00%.2f 1000.00%.2f\n", ANSL,ANSR); the }Bayi the intMain () the { - while(SCANF ("%d", &n) = =1) - { the for(intI=1; i<=n;i++) C[i].read (); the solve (); the } the return 0; -}
UVA 11853 paintball--(dfs+ round)