这道题真的不难,但是细节挺多(具体见程序)
题目本身而言,显然是个费用流模型(或者写KM)

 type node=record
point,next,flow,cost:longint;
end; var p,x,y,pre,cur,d:array[..] of longint;
v:array[..] of boolean;
q:array[..] of longint;
edge:array[..] of node;
a:array[..,..] of longint;
na:array[..] of string[];
t,n,i,len,j,k:longint;
ef:boolean;
s:string;
ch:char; function find(x:string):longint;
var i:longint;
begin
for i:= to *n do
if na[i]=x then exit(i);
end; function check(l,r:longint):boolean;
var i:longint;
begin
for i:= to *n do
if (i<>l) and (i<>r) then
if ((x[i]<=x[l]) and (x[i]>=x[r])) or ((x[i]>=x[l]) and (x[i]<=x[r])) then
if ((y[i]<=y[l]) and (y[i]>=y[r])) or ((y[i]>=y[l]) and (y[i]<=y[r])) then
if (x[i]-x[l])*(y[i]-y[r])=(x[i]-x[r])*(y[i]-y[l]) then
begin //注意是线段上的点
exit(false);
end;
exit(true);
end; procedure add(x,y,f,w:longint);
begin
inc(len);
edge[len].point:=y;
edge[len].flow:=f;
edge[len].cost:=w;
edge[len].next:=p[x];
p[x]:=len;
end; function spfa:boolean;
var i,j,f,r,x,y:longint;
begin
for i:= to t do
d[i]:=-;
d[]:=;
f:=;
r:=;
fillchar(v,sizeof(v),false);
q[]:=;
v[]:=true;
while f<=r do
begin
x:=q[f];
v[x]:=false;
i:=p[x];
while i<>- do
begin
y:=edge[i].point;
if edge[i].flow> then
if d[x]+edge[i].cost>d[y] then
begin
pre[y]:=x;
cur[y]:=i;
d[y]:=d[x]+edge[i].cost;
if not v[y] then
begin
inc(r);
q[r]:=y;
v[y]:=true;
end;
end;
i:=edge[i].next;
end;
inc(f);
end;
if d[t]=- then exit(false) else exit(true);
end; function maxcost:longint;
var i,j:longint;
begin
maxcost:=;
while spfa do
begin
maxcost:=maxcost+d[t];
i:=t;
while i<> do
begin
j:=cur[i];
dec(edge[j].flow);
inc(edge[j xor ].flow);
i:=pre[i];
end;
end;
end; begin
len:=-;
fillchar(p,sizeof(p),);
readln(k);
readln(n);
for i:= to *n do
begin
readln(x[i],y[i],ch,na[i]);
for j:= to length(na[i]) do
na[i][j]:=upcase(na[i][j]); //注意不区分大小写
end;
t:=*n+;
for i:= to n do
begin
add(,i,,);
add(i,,,);
add(i+n,t,,);
add(t,i+n,,);
end; for i:= to n do
for j:=n+ to *n do
a[i,j]:=; //注意
ef:=true;
while ef do
begin
s:='';
read(ch);
while ch<>' ' do
begin
s:=s+upcase(ch);
if s='END' then ef:=false; //大坑,有的人名字里会带end
read(ch);
if not ef and (ord(ch)>=) then
ef:=true
else if not ef then break;
end;
if not ef then break;
i:=find(s);
s:='';
read(ch);
while ch<>' ' do
begin
s:=s+upcase(ch);
read(ch);
end;
j:=find(s);
readln(a[i,j]);
a[j,i]:=a[i,j];
end;
for i:= to n do
for j:=n+ to *n do
if (sqr(x[i]-x[j])+sqr(y[i]-y[j])<=sqr(k)) and check(i,j) then
begin
add(i,j,,a[i,j]);
add(j,i,,-a[i,j]);
end;
writeln(maxcost);
end.

bzoj2539的更多相关文章

  1. BZOJ2539: [Ctsc2000]丘比特的烦恼

    BZOJ2539: [Ctsc2000]丘比特的烦恼 Description 随着社会的不断发展,人与人之间的感情越来越功利化. 最近,爱神丘比特发现,爱情也已不再是完全纯洁的了. 这使得丘比特很是苦 ...

  2. KM算法及其优化的学习笔记&&bzoj2539: [Ctsc2000]丘比特的烦恼

    感谢  http://www.cnblogs.com/vongang/archive/2012/04/28/2475731.html 这篇blog里提供了3个链接……基本上很明白地把KM算法是啥讲清楚 ...

  3. BZOJ2539 Spoj 10707 Count on a tree II

    题面 题解 因为这道题目我也不太会做,所以借鉴了一下大佬heyujun的博客 如果不强制在线,这道题目是树上莫队练手题 我们知道莫队是离线的,但是万一强制在线就凉凉了 于是我们就需要一些操作:树分块 ...

  4. bzoj2539 丘比特的烦恼、黑书P333 (最优二分图匹配)

      丘比特的烦恼 题目描述 Description 随着社会的不断发展,人与人之间的感情越来越功利化.最近,爱神丘比特发现,爱情也已不再是完全纯洁的了.这使得丘比特很是苦恼,他越来越难找到合适的男女, ...

随机推荐

  1. IOS-CGAffineTransformMake 矩阵变换 的运算原理

    1.矩阵的基本知识: struct CGAffineTransform {   CGFloat a, b, c, d;   CGFloat tx, ty; }; CGAffineTransform C ...

  2. CSS控制鼠标滑过时的效果

    用css控制鼠标样式的语法如下:<span style="cursor:*">文本或其它页面元素</span>把 * 换成如下15个效果的一种: 下面是对这 ...

  3. windows服务,安装、启动、停止,配置,一个批处理文件搞定

    相对而言,还是比较通用的吧,如果哪位仁兄有更好的实现方式,或者发现有不足之处,还请多多指教.  @echo off echo.------------------------------------- ...

  4. CI 笔记3 (easyui 的layout布局,最小化layout原型)

    在做easyui的layout的布局时,最小化一个原型,分2步,一个是div的父标签,一个是body做父标签,全屏的. 步骤分别为: 在设置的5个区中,div的最后一个,必须是data-options ...

  5. oracle模糊查询效率可这样提高

    1.使用两边加'%'号的查询,oracle是不通过索引的,所以查询效率很低. 例如:select count(*) from lui_user_base t where t.user_name lik ...

  6. 【转】iOS-Core-Animation-Advanced-Techniques(六)

    原文:http://www.cocoachina.com/ios/20150106/10839.html 基于定时器的动画和性能调优 基于定时器的动画 我可以指导你,但是你必须按照我说的做. -- 骇 ...

  7. c读写文件相关

    1.打开文件: 函数原型: FILE * fopen(const char * path,const char * mode); 返回值: 文件顺利打开后,指向该流的文件指针就会被返回.如果文件打开失 ...

  8. 【POJ2752】【KMP】Seek the Name, Seek the Fame

    Description The little cat is so famous, that many couples tramp over hill and dale to Byteland, and ...

  9. CentOS中vsftp安装、配置、卸载

    1. 安装VSFTP 1 [root@localhost ~]# yum -y install vsftpd 2. 配置vsftpd.conf文件 [root@localhost ~]# vi /et ...

  10. html 标签的嵌套规则

    1. 块元素可以包含内联元素或某些块元素,但内联元素却不能包含块元素,它只能包含其它的内联元素: <div><h1></h1><p></p> ...