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