POJ 1066 Treasure Hunt [idea title]

Source: Internet
Author: User

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 &AMP;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 &AMP;BB,ConstNode &AMP;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]

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.