HDU 1086 You can Solve a Geometry Problem too (determine the intersection of line segments)

Source: Internet
Author: User

HDU 1086 You can Solve a Geometry Problem too (determine the intersection of line segments)

Address: HDU 1086

In this case, I wrote more than 2 k B code to determine the intersection of line segments .. Is it a waste... But I don't think I can optimize it any more ....

The cross product is used to determine the intersection of line segments. If the two line segments are L1 and L2, calculate the cross product of the vectors of one of L1 and L2 endpoints and one of L1 endpoints first. If the product of the two cross products is less than 0, it indicates that L1 is between two L2 endpoints, but at this time it is not guaranteed to be intersecting. In this case, you need to use the same method to determine whether L2 is between two L1 endpoints. If L2 is also between two L1 endpoints, it is enough to indicate that L1 and L2 are at the same intersection. However, you still need to determine whether the endpoint is also the same. At that time, you did not expect this, resulting in a period of time .. As for the determination of the endpoint, I did not expect any good methods .. It directly judges whether the four endpoints are the same ..

The Code is as follows:

#include 
 
  #include 
  
   #include 
   
    #include 
    
     #include 
     
      #include 
      
       #include 
       
        #include 
        
         #include 
         #include 
          
           #include using namespace std;#define eqs 1e-10struct node{ double x, y;} point[1000];node xiang(node a, node b){ node f1; f1.x=a.x-b.x; f1.y=a.y-b.y; return f1;}int cross(node a, node b){ double c; c= a.x*b.y-a.y*b.x; if(c>0) return 1; else if(c==0) return 0; else return -1;}int dcmp(double x, double y){ if(fabs(x-y)<=eqs) return 1; return 0;}int main(){ int n, i, j; int c1, c2, c3, c4, ans; while(scanf("%d",&n)!=EOF&&n) { ans=0; for(i=0; i
           
            

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.