这道题真的不难,但是细节挺多(具体见程序)
题目本身而言,显然是个费用流模型(或者写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.

最新文章

  1. 【码在江湖】前端少侠的json故事(上)日月第一击
  2. 父子页面之间元素相互操作(iframe子页面)
  3. css雪碧图生成工具4.1更新
  4. 【初探HTML本相】道之真谛不过自然,html标签脱俗还真
  5. 58种jQuery模拟CSS3过渡页面切换特效
  6. nios II--实验1——hello_world硬件部分
  7. [CTO]创业团队CTO应具备的素质
  8. CodeForces 370A Rook, Bishop and King
  9. 一个很奇特的异常 tmpFile.renameTo(classFile) failed
  10. Please read “Security” section of the manual to find out how to run mysqld as root!错误解决(转)
  11. 使用Asponse.Cell解决Excel科学计数法问题
  12. java包(package)
  13. Vue.js中组件传参的方法 - 基于webpack模板
  14. Python的HTTP服务实例
  15. IBM的websphere MQ的c#使用(一)
  16. 【转】matlab图形句柄详解(一)
  17. spring mvc+redis实现微信小程序登录
  18. 树莓派安装vnc server并设置自启动
  19. 10 Free Image Hosting Sites for Your Photos
  20. 并发之ThreadLocal

热门文章

  1. 浏览器中JavaScript执行原理
  2. 浅谈inline-block
  3. CSS3 box-sizing 属性
  4. power desinger 学习笔记&lt;六&gt;
  5. ReactiveCocoa入门教程——第一部分
  6. Java中实现对象的比较:Comparable接口和Comparator接口
  7. slf4j与log4j
  8. SGU 124.Broken line
  9. 再看IOC, 读深入理解DIP、IoC、DI以及IoC容器
  10. overflow第一次觉得你有点可恶