UVA 11853 paintball--(dfs+ round)

Source: Internet
Author: User

  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)

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.