题目:
https://icpcarchive.ecs.baylor.edu/external/40/4043.pdf
样例运行结果与sample output不一样,坑死了。
const int INF =0x3f3f3f3f;
const int maxn= 100+10 ;
//const int maxm= ;
//by yskysker123
int n;
struct
{
double x;
double y;
} a[maxn],b[maxn];
int lef[maxn];
double w[maxn][maxn];
double Lx[maxn],Ly[maxn];
bool S[maxn],T[maxn];
int ans[maxn];
bool eq(double a, double b) {
return fabs(a-b) < 1e-9;
}
bool match(int i)
{
S[i]=true;
for(int j=1;j<=n;j++)
{
if(eq(Lx[i]+Ly[j], w[i][j])&&!T[j])
{
T[j]=1;
if(!lef[j]||match(lef[j] ))
{
lef[j]=i;
return true;
}
}
}
return false;
}
void update()
{
double a=INF;
for(int i=1;i<=n;i++)
{
if(!S[i]) continue;
for(int j=1;j<=n;j++)
{
if(T[j]) continue;
a=min(a,Lx[i]+Ly[j]-w[i][j]);
}
}
for(int i=1;i<=n;i++)
{
if(S[i]) Lx[i]-=a;
if(T[i]) Ly[i]+=a;
}
}
void KM()
{
for(int i=1;i<=n;i++)
{
lef[i]=Lx[i]=Ly[i]=0;
for(int j=1;j<=n;j++)
{
Lx[i]=max(Lx[i],w[i][j]);
}
}
for(int i=1;i<=n;i++)
{
for(;;)
{
for(int j=1;j<=n;j++)
S[j]=T[j]=0;
if(match(i)) break;
else update();
}
}
}
int main()
{
int kase=0;
while(~scanf("%d",&n))
{
if(kase++>0) puts("");
for(int i=1;i<=n;i++)
{
scanf("%lf%lf",&a[i].x,&a[i].y);
}
for(int i=1;i<=n;i++)
{
scanf("%lf%lf",&b[i].x,&b[i].y);
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
w[i][j]= -sqrt( sqr(a[i].x-b[j].x) + sqr(a[i].y-b[j].y) ) ;
}
}
KM();
for(int i=1;i<=n;i++)
{
ans[lef[i] ]=i;
}
for(int i=1;i<=n;i++)
{
printf("%d\n",ans[i]);
}
}
return 0;
}
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<climits>
#include<queue>
#include<vector>
#include<map>
#include<sstream>
#include<set>
#include<stack>
#include<utility>
#pragma comment(linker, "/STACK:102400000,102400000")
#define PI 3.1415926535897932384626
#define eps 1e-10
#define sqr(x) ((x)*(x))
#define FOR0(i,n) for(int i=0 ;i<(n) ;i++)
#define FOR1(i,n) for(int i=1 ;i<=(n) ;i++)
#define FORD(i,n) for(int i=(n) ;i>=0 ;i--)
#define lson num<<1,le,mid
#define rson num<<1|1,mid+1,ri
#define MID int mid=(le+ri)>>1
#define zero(x)((x>0? x:-x)<1e-15)
#define mk make_pair
#define _f first
#define _s second
using namespace std;
//const int INF= ;
typedef long long ll;
//const ll inf =1000000000000000;//1e15;
//ifstream fin("input.txt");
//ofstream fout("output.txt");
//fin.close();
//fout.close();
//freopen("a.in","r",stdin);
//freopen("a.out","w",stdout);