题意:在靠近南极的某处,一些企鹅站在许多漂浮的冰块上。由于企鹅是群居动物,所以它们想要聚集到一起,在同一个冰块上。企鹅们不想把自己的身体弄湿,所以它们在冰块之间跳跃,但是它们的跳跃距离,有一个上限。 
随着气温的升高,冰块开始融化,并出现了裂痕。而企鹅跳跃的压力,使得冰块的破裂加速。幸运的是,企鹅对冰块十分有研究,它们能知道每块冰块最多能承受多少次跳跃。对冰块的损害只在跳起的时候产生,而落地时并不对其产生伤害。 
现在让你来帮助企鹅选择一个冰面使得它们可以聚集到一起。

第一行整数N,和浮点数D,表示冰块的数目和企鹅的最大跳跃距离。 

(1≤N ≤100) (0 ≤D ≤100 000), 
接下来N行,xi, yi, ni and mi,分别表示冰块的X和Y坐标,该冰块上的企鹅数目,以及还能承受起跳的次数。

输出所有可能的相聚冰块的编号,以0开始。如果不能相遇,输出-1。

思路:这道题是一年前上课最大流的例题,如果去年就拿了一等多好

考虑强行限制起跳次数很难,尝试裂点

将每块冰都裂成两个点(i,1),(i,2)

(i,1)-->(i,2)连流量为m[i]的边

对于原来在冰面上的企鹅,建立超级源S

s-->(i,1)连流量为n[i]的边

对于平面距离小于D的两点i,j

(i,2)-->(j,1)连流量为maxlongint的边

枚举(j,1)作为汇点判断最大流量是否>=企鹅总数即可

 var head,vet,next,gap,dis,len,c,fan,a,b,save:array[..]of longint;
x,y:array[..]of double;
num:array[..,..]of longint;
n,m,qq,tot,i,j,ans,v,cas,s,source,src,st:longint;
d:double; procedure add(a,b,c:longint);
begin
inc(tot);
next[tot]:=head[a];
vet[tot]:=b;
len[tot]:=c;
head[a]:=tot;
end; function min(x,y:longint):longint;
begin
if x<y then exit(x);
exit(y);
end; function dfs(u,aug:longint):longint;
var e,v,flow,t,val:longint;
begin
if u=src then exit(aug);
e:=head[u]; flow:=; val:=s-;
while e<> do
begin
v:=vet[e];
if len[e]> then
begin
if dis[u]=dis[v]+ then
begin
t:=dfs(v,min(len[e],aug-flow));
len[e]:=len[e]-t;
len[fan[e]]:=len[fan[e]]+t;
flow:=flow+t;
if dis[source]>=s then exit(flow);
if aug=flow then break;
end;
val:=min(val,dis[v]);
end;
e:=next[e];
end;
if flow= then
begin
dec(gap[dis[u]]);
if gap[dis[u]]= then dis[source]:=s;
dis[u]:=val+;
inc(gap[dis[u]]);
end;
exit(flow);
end; function maxflow:longint;
var ans:longint;
begin
fillchar(dis,sizeof(dis),);
fillchar(gap,sizeof(gap),);
gap[]:=s; ans:=;
while dis[source]<s do ans:=ans+dfs(source,maxlongint);
exit(ans);
end; begin
assign(input,'poj3498.in'); reset(input);
assign(output,'poj3498.out'); rewrite(output);
readln(cas);
for v:= to cas do
begin
fillchar(head,sizeof(head),);
tot:=; qq:=; s:=;
read(n,d);
for i:= to n do
begin
read(x[i],y[i],a[i],b[i]);
qq:=qq+a[i];
end;
for i:= to n do
begin
inc(s); num[i,]:=s;
inc(s); num[i,]:=s;
end;
inc(s); st:=s;
for i:= to n do
for j:= to n do
if (i<>j)and(sqrt(sqr(x[i]-x[j])+sqr(y[i]-y[j]))<=d) then
begin
fan[tot+]:=tot+;
fan[tot+]:=tot+;
add(num[i,],num[j,],maxlongint);
add(num[j,],num[i,],);
end;
for i:= to n do
begin
fan[tot+]:=tot+;
fan[tot+]:=tot+;
add(num[i,],num[i,],b[i]);
add(num[i,],num[i,],);
end;
for i:= to n do
begin
fan[tot+]:=tot+;
fan[tot+]:=tot+;
add(st,num[i,],a[i]);
add(num[i,],st,);
end;
source:=st; ans:=;
for i:= to tot do save[i]:=len[i];
for i:= to n do
begin
src:=num[i,];
if maxflow>=qq then
begin
inc(ans); c[ans]:=i;
end;
for j:= to tot do len[j]:=save[j];
end;
if ans= then writeln(-)
else
begin
for i:= to ans- do write(c[i]-,' ');
write(c[ans]-);
writeln;
end;
end;
close(input);
close(output);
end.

【POJ3498】March of the Penguins(最大流,裂点)的更多相关文章

  1. poj 3498 March of the Penguins(拆点+枚举汇点 最大流)

    March of the Penguins Time Limit: 8000MS   Memory Limit: 65536K Total Submissions: 4873   Accepted: ...

  2. [POJ 3498] March of the Penguins

    March of the Penguins Time Limit: 8000MS   Memory Limit: 65536K Total Submissions: 4378   Accepted:  ...

  3. POJ 3498 March of the Penguins(网络最大流)

    Description Somewhere near the south pole, a number of penguins are standing on a number of ice floe ...

  4. poj 3498 March of the Penguins(最大流+拆点)

    题目大意:在南极生活着一些企鹅,这些企鹅站在一些冰块上,现在要让这些企鹅都跳到同一个冰块上.但是企鹅有最大的跳跃距离,每只企鹅从冰块上跳走时会给冰块造成损害,因此企鹅跳离每个冰块都有次数限制.找出企鹅 ...

  5. UVALive-3972 March of the Penguins (最大流:节点容量)

    题目大意:有n个带有裂缝的冰块.已知每个冰块的坐标和已经站在上面的企鹅数目,每当一个企鹅从一个冰块a跳到另一个冰块b上的时候,冰块a上的裂缝便增大一点,还知道每个冰块上最多能被跳跃的次数.所有的企鹅都 ...

  6. POJ3498:March of the Penguins——题解

    最近的题解的故事背景割. 题目: 描述 在靠近南极的某处,一些企鹅站在许多漂浮的冰块上.由于企鹅是群居动物,所以它们想要聚集到一起,在同一个冰块上.企鹅们不想把自己的身体弄湿,所以它们在冰块之间跳跃, ...

  7. March of the Penguins

    poj3498:http://poj.org/problem?id=3498 题意:某个冰块上有a只企鹅,总共可以跳出去b只,问是否可能所有的企鹅都跳到某一块冰块上,输出所有的可能的冰块的编号. 由于 ...

  8. hdu 2334 March of the Penguins

      题意大意 在X,Y坐标系中有N(N<=100)个冰块,有些冰块上有1若干只企鹅,每只企鹅一次最多跳M距离,一个冰块在有Mi个企鹅离开,就会消失,问有哪些冰块可以作为集合点,就是所有企鹅都能成 ...

  9. UVA 12125 March of the Penguins

    题意: 给定一些冰块,每个冰块上有一些企鹅,每个冰块有一个可以跳出的次数限制,每个冰块位于一个坐标,现在每个企鹅跳跃力为d,问所有企鹅能否跳到一点上,如果可以输出所有落脚冰块,如果没有方案就打印-1 ...

随机推荐

  1. Node.js 中文学习资料和教程导航

    这篇文章来自 Github 上的一位开发者收集整理的 Node.js 中文学习资料和教程导航.Node 是一个服务器端 JavaScript 解释器,它将改变服务器应该如何工作的概念,它的目标是帮助程 ...

  2. Bootstrap 缩略图

    <!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...

  3. 01_5_删除指定id的单个对象

    01_5_删除指定id的单个对象 1. 配置相应的映射文件内容 <delete id="deleteStudent" parameterClass="int&quo ...

  4. Objective-C实现一个简单的栈

    栈作为一种数据结构,是一种只能在一端进行插入和删除操作的特殊线性表.它按照先进后出的原则存储数据,先进入的数据被压入栈底,最后的数据在栈顶,需要读数据的时候从栈顶开始弹出数据(最后一个数据被第一个读出 ...

  5. odoo10 api 装饰器

    http://www.cnblogs.com/kfx2007/p/3894297.html one:装饰record-style方法中的self为单一实例,被装饰的方法将会在每一条记录中循环调用,返回 ...

  6. 【差分约束】poj1275Cashier Employment

    比较经典的差分约束 Description A supermarket in Tehran is open 24 hours a day every day and needs a number of ...

  7. MySQL 使用GTID进行复制

    MySQL 使用GTID进行复制 1. GTID的格式和存储 1.1 GTID 集 1.2 mysql.gtid_executed 表 1.3 mysql.gtid_executed 表压缩 2. G ...

  8. ipmitool的使用

    https://www.ibm.com/developerworks/cn/linux/l-ipmi/index.html

  9. destoon 短信发送函数及短信接口修改

    // $DT在common.inc.php中定义, $CACHE = cache_read('module.php'); $DT = $CACHE['dt'];  从缓存里读取网站配置信息. //$d ...

  10. GoF23种设计模式之结构型模式之代理模式

    一.概述 为其他对象提供一种代理以控制对这个对象的访问. 二.适用性 1.远程代理(RemoteProxy):为一个对象在不同的地址空间土工局部代表. 2.虚代理(VirtualProxy):根据需要 ...