这就很裸了
只是坑点实在多
坐标有实数
字串大小写
不可连的边设为-inf
貌似题目保证有完备匹配?
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<map>
#include<string>
#define cl(x) memset(x,0,sizeof(x))
using namespace std;
const int N=35;
int n,ans,w[N][N];
int boy[N],lx[N],ly[N],sla[N];
int S[N],T[N];
inline bool match(int u){
S[u]=1;
for (int v=1;v<=n;v++){
if (T[v]) continue;
if (lx[u]+ly[v]==w[u][v]){
T[v]=1;
if (!boy[v] || match(boy[v]))
return boy[v]=u,1;
}
else
sla[v]=min(sla[v],lx[u]+ly[v]-w[u][v]);
}
return 0;
}
inline int KM()
{
cl(boy); cl(ly);
for (int i=1;i<=n;i++)
{
lx[i]=-1<<30;
for (int j=1;j<=n;j++) lx[i]=max(lx[i],w[i][j]);
}
for (int i=1;i<=n;i++)
{
for (int j=1;j<=n;j++) sla[j]=1<<30;
for (;;)
{
cl(S); cl(T);
if (match(i)) break;
int a=1<<30;
for (int j=1;j<=n;j++) if (!T[j]) a=min(a,sla[j]);
for (int j=1;j<=n;j++) if (S[j]) lx[j]-=a;
for (int j=1;j<=n;j++) if (T[j]) ly[j]+=a; else sla[j]-=a;
}
}
int ret=0;
for (int i=1;i<=n;i++) if (boy[i]) ret+=w[boy[i]][i];
return ret;
}
void ToUpperString(string &str)
{
transform(str.begin(), str.end(), str.begin(), (int (*)(int))toupper);
}
inline int dcmp(double a,double b){
if (fabs(a-b)<1e-6) return 0;
if (a<b) return -1; return 1;
}
inline double sqr(double a){ return a*a; }
struct Point{
double x,y;
Point(double x=0,double y=0):x(x),y(y) { }
void read() { cin>>x>>y; }
friend Point operator - (Point A,Point B){
return Point(A.x-B.x,A.y-B.y);
}
friend double operator * (Point A,Point B){
return A.x*B.y-B.x*A.y;
}
friend double Dist(Point A,Point B){
return sqrt(sqr(A.x-B.x)+sqr(A.y-B.y));
}
friend bool Jud(Point p0,Point p1,Point p2){
double x1,x2;
x1=p1.x; x2=p2.x; if (x1>x2) swap(x1,x2);
if (!(dcmp(x1,p0.x)<=0 && dcmp(p0.x,x2)<=0)) return 0;
x1=p1.y; x2=p2.y; if (x1>x2) swap(x1,x2);
if (!(dcmp(x1,p0.y)<=0 && dcmp(p0.y,x2)<=0)) return 0;
return dcmp((p1-p0)*(p2-p0),0)==0;
}
}sx[N],sy[N];
map<string,int> Name;
double K;
int main()
{
string name; int iu,iv;
freopen("t.in","r",stdin);
freopen("t.out","w",stdout);
cin>>K>>n;
for (int i=1;i<=n;i++){
sx[i].read(); cin>>name; ToUpperString(name); Name[name]=i;
}
for (int i=1;i<=n;i++){
sy[i].read(); cin>>name; ToUpperString(name); Name[name]=n+i;
}
for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) w[i][j]=1;
while (1)
{
cin>>name; if (name==string("End")) break;
ToUpperString(name); iu=Name[name]; cin>>name; ToUpperString(name); iv=Name[name];
if (iu>iv) swap(iu,iv);
iv-=n;
cin>>w[iu][iv];
}
for (int i=1;i<=n;i++)
for (int j=1;j<=n;j++)
for (int k=1;k<=n;k++)
{
if (dcmp(Dist(sx[i],sy[j]),K)>0)
w[i][j]=-1e8;
else if (k!=i && Jud(sx[k],sx[i],sy[j]))
w[i][j]=-1e8;
else if (k!=j && Jud(sy[k],sx[i],sy[j]))
w[i][j]=-1e8;
}
ans=KM();
printf("%d\n",ans);
return 0;
}