Title Link: http://poj.org/problem?id=1066
--------------------------------------------------------------------------------------------------------
This problem may be after the first look at how to build the shortest circuit after the map
But it's not just the code that's going to be complicated, but there's the possibility of some bad judgment.
But think about it. We can find the following properties
If the start and end points are on either side of an obstacle segment, then this segment has and only once crossed
So you get the answer by counting the number of line segments crossing the starting and ending lines.
And since the input is guaranteed to be integers, we only use the midpoint as the starting point for enumerating all the adjacent points on the boundary.
1#include <cstdio>2#include <cstring>3#include <cmath>4#include <algorithm>5 using namespacestd;6 structnode7 {8 Doublex, y;9}a[ -], B, C;Ten DoubleCrossConstNode &aa,ConstNode &BB,ConstNode &cc) One { A return(bb.x-aa.x) * (CC.Y-AA.Y)-(BB.Y-AA.Y) * (cc.x-aa.x); - } - BOOLCheckConstNode &aa,ConstNode &BB,ConstNode &CC,ConstNode &dd) the { - returnCross (AA, BB, cc) * Cross (AA, BB, DD) <0; - } - intN, ans = -, CNT; + intMain () - { +scanf"%d", &n); A for(inti =1; I <= (n <<1); ++i) atscanf"%LF%LF", &a[i].x,&a[i].y); -scanf"%LF%LF", &b.x, &b.y); - for(inti =0; I < -; ++i) - { -CNT =0; -c.x =0.5+i; inC.Y =0; - for(intj =1; J < (n <<1); J + =2) to if(Check (A[j], a[j +1], B, c)) +++CNT; -Ans =min (ans, cnt); theCNT =0; *c.x =0.5+i; $C.Y = -;Panax Notoginseng for(intj =1; J < (n <<1); J + =2) - if(Check (A[j], a[j +1], B, c)) the++CNT; +Ans =min (ans, cnt); ACNT =0; theC.Y =0.5+i; +c.x =0; - for(intj =1; J < (n <<1); J + =2) $ if(Check (A[j], a[j +1], B, c)) $++CNT; -Ans =min (ans, cnt); -CNT =0; theC.Y =0.5+i; -c.x = -;Wuyi for(intj =1; J < (n <<1); J + =2) the if(Check (A[j], a[j +1], B, c)) -++CNT; WuAns =min (ans, cnt); - } Aboutprintf"Number of doors =%d\n", ans +1); $ return 0; -}
POJ 1066 Treasure Hunt [idea title]