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

第一行整数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. c++ 读取文件 最后一行读取了两次

    用ifstream的eof(),竟然读到文件最后了,判断eof还为false.网上查找资料后,终于解决这个问题. 参照文件:http://tuhao.blogbus.com/logs/21306687 ...

  2. 看了下opengl相关的资料,踩了一个坑,记录一下

    2019/03/10 下午看了下关于opengl的资料,然后把敲了下代码,然后程序报错了.代码如下: #include <glad/glad.h> #include <GLFW/gl ...

  3. destoon后台权限-不给客户创始人权限并屏蔽部分功能

    1.根目录下后台入口文件admin.php $_founder = $CFG['founderid'] == $_userid ? $_userid : 0;  //  $CFG['founderid ...

  4. 【Linux命令】nohup和&差异,查看进程和终止进程!

    最近在开发dueros的技能,官方提供的PHPSDK中有多个实力,而运行实例的命令如下是 nohup php -S 0.0.0.0:8029 myindex.php & 从命令来看,肯定是在8 ...

  5. 经典MSSQL语句大全和常用SQL语句命令的作用

    下列语句部分是Mssql语句,不可以在access中使用. SQL分类: DDL类型包括数据库.表的创建,修改,删除,声明—数据定义语言(CREATE,ALTER,DROP,DECLARE) DML类 ...

  6. LeetCode(225) Implement Stack using Queues

    题目 Implement the following operations of a stack using queues. push(x) – Push element x onto stack. ...

  7. HDU - 1496 Equations (hash)

    题意: 多组测试数据. 每组数据有一个方程 a*x1^2 + b*x2^2 + c*x3^2 + d*x4^2 = 0,方程中四个未知数 x1, x2, x3, x4 ∈ [-100, 100], 且 ...

  8. Linux学习-以最新核心版本编译 CentOS 7.x 的核心

    为了某些缘故需要最新的 4.x.y 的核心版本来实作某些特定的功能时,那该 如何是好?没办法,只好使用最新的核心版本来编译你可以依照上面的程序来一个一个处理, 没有问题~不过,你也可以根据 ELRep ...

  9. Linux学习-磁盘配额 (Quota) 的应用与实作

    什么是 Quota 在 Linux 系统中,由于是多人多任务的环境,所以会有多人共同使用一个硬盘空间的情况发生, 如 果其中有少数几个使用者大量的占掉了硬盘空间的话,那势必压缩其他使用者的使用权力! ...

  10. .Net Task常见问题

    最近尝试使用一下Task,但是使用过程中因为API的不熟悉碰到了很多问题,不清楚什么时间来调用Task.Start(),具体该怎么使用等等. 如下所描述的Task.Start()方法均为实例方法. 1 ...