【POJ3498】March of the Penguins(最大流,裂点)
题意:在靠近南极的某处,一些企鹅站在许多漂浮的冰块上。由于企鹅是群居动物,所以它们想要聚集到一起,在同一个冰块上。企鹅们不想把自己的身体弄湿,所以它们在冰块之间跳跃,但是它们的跳跃距离,有一个上限。
随着气温的升高,冰块开始融化,并出现了裂痕。而企鹅跳跃的压力,使得冰块的破裂加速。幸运的是,企鹅对冰块十分有研究,它们能知道每块冰块最多能承受多少次跳跃。对冰块的损害只在跳起的时候产生,而落地时并不对其产生伤害。
现在让你来帮助企鹅选择一个冰面使得它们可以聚集到一起。
(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(最大流,裂点)的更多相关文章
- poj 3498 March of the Penguins(拆点+枚举汇点 最大流)
March of the Penguins Time Limit: 8000MS Memory Limit: 65536K Total Submissions: 4873 Accepted: ...
- [POJ 3498] March of the Penguins
March of the Penguins Time Limit: 8000MS Memory Limit: 65536K Total Submissions: 4378 Accepted: ...
- POJ 3498 March of the Penguins(网络最大流)
Description Somewhere near the south pole, a number of penguins are standing on a number of ice floe ...
- poj 3498 March of the Penguins(最大流+拆点)
题目大意:在南极生活着一些企鹅,这些企鹅站在一些冰块上,现在要让这些企鹅都跳到同一个冰块上.但是企鹅有最大的跳跃距离,每只企鹅从冰块上跳走时会给冰块造成损害,因此企鹅跳离每个冰块都有次数限制.找出企鹅 ...
- UVALive-3972 March of the Penguins (最大流:节点容量)
题目大意:有n个带有裂缝的冰块.已知每个冰块的坐标和已经站在上面的企鹅数目,每当一个企鹅从一个冰块a跳到另一个冰块b上的时候,冰块a上的裂缝便增大一点,还知道每个冰块上最多能被跳跃的次数.所有的企鹅都 ...
- POJ3498:March of the Penguins——题解
最近的题解的故事背景割. 题目: 描述 在靠近南极的某处,一些企鹅站在许多漂浮的冰块上.由于企鹅是群居动物,所以它们想要聚集到一起,在同一个冰块上.企鹅们不想把自己的身体弄湿,所以它们在冰块之间跳跃, ...
- March of the Penguins
poj3498:http://poj.org/problem?id=3498 题意:某个冰块上有a只企鹅,总共可以跳出去b只,问是否可能所有的企鹅都跳到某一块冰块上,输出所有的可能的冰块的编号. 由于 ...
- hdu 2334 March of the Penguins
题意大意 在X,Y坐标系中有N(N<=100)个冰块,有些冰块上有1若干只企鹅,每只企鹅一次最多跳M距离,一个冰块在有Mi个企鹅离开,就会消失,问有哪些冰块可以作为集合点,就是所有企鹅都能成 ...
- UVA 12125 March of the Penguins
题意: 给定一些冰块,每个冰块上有一些企鹅,每个冰块有一个可以跳出的次数限制,每个冰块位于一个坐标,现在每个企鹅跳跃力为d,问所有企鹅能否跳到一点上,如果可以输出所有落脚冰块,如果没有方案就打印-1 ...
随机推荐
- C#4.0中的dynamic关键字和ExpandoObject对象
dynamic最大的特点我想莫过于在它的类型在运行时才确定,这也是它与往静态类型关键字的最大区别.如果你在你的代码操作中用到了dynamic关键字去定义一个变量时,那么这个变量在编译的时候编译器不会对 ...
- oracle 将查询结果输出到txt文件里
在查询语句里先输入spool filepath 中间是需要查询的语句,最后spool off 就会把中间查询的结果都输入到file文件里 spool E:\log.txt; select id,nam ...
- vector总结(更新中。。。)
vector中这两个属性很容易弄混淆. size是当前vector容器真实占用的大小,也就是容器当前拥有多少个容器. capacity是指在发生realloc前能允许的最大元素数,即预分配的内存空间. ...
- 标准C++(2)
一.类 C++是一种面向对象的语言,它在C语言的基础上添加了一种新的数据结构,类 ——class class是一种复合型的数据结构 它能够由不同类型的变量及函数组成 C++中的class与struct ...
- 【js】【vue】获取当前dom层
多层嵌套,$event.currentTarget 指当前点击层
- 用Python设置matplotlib.plot的坐标轴刻度间隔以及刻度范围
一.用默认设置绘制折线图 import matplotlib.pyplot as plt x_values=list(range(11)) #x轴的数字是0到10这11个整数 y_values=[x* ...
- 20181206(re,正则表达式,哈希)
1.re&正则表达式 2.hashlib 一:re模块&正则表达式 正则:正则就是用一些具有特殊含义的符号组合到一起(称为正则表达式)来描述字符或者字符串的方法.或者说:正则就是用来描 ...
- leetcode-21-knapsack
322. Coin Change Write a function to compute the fewest number of coins that you need to make up tha ...
- IE6 单文件绿色版
IE6单文件绿色版,可以直接运行,无需安装,完美兼容Win10(自带2016年1月更新). https://www.lanzous.com/i3w7dej
- MAC OS X 终端命令入门
在这里记下..防止丢失 pwd 当前工作目录 cd(不加参数) 进root cd(folder) 进入文件夹 cd .. 上级目录 cd ~ 返回root cd - 返回上一个访问的目录 rm 文件名 ...