Poj 3565 Ants KM

Source: Internet
Author: User

Poj 3565 Ants KM

Question:

Give the coordinates of n ant and n class apple trees. To let each ant go to an apple tree, the route cannot be repeated. a feasible solution is proposed.

Analysis:

When the distance and the smallest value of a matching feasible ant are obtained, the KM algorithm can be directly used to find the matching of the minimum weight of a bipartite graph. Another approach is to assume a match first, and adjust it if there is a cross.

Code:

//poj 3565//sep9#include 
 
  #include 
  
   using namespace std;const int maxN=128;const double INF=999999999.0;double w[maxN][maxN],lx[maxN],ly[maxN],slack[maxN];int linky[maxN];int visx[maxN],visy[maxN];int nx,ny;double antX[maxN],antY[maxN],appleX[maxN],appleY[maxN];int ans[maxN];bool find(int x){visx[x]=true;for(int y=0;y
   
    t)slack[y]=t;}return false;}int KM(){int i,j;memset(linky,-1,sizeof(linky));for(i=0;i
    
     lx[i])lx[i]=w[i][j];for(int x=0;x
     
      

Related Article

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.