【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 ...
随机推荐
- Java基础面试题: 份证号码组成规则是前4位是代表省份和地区 编写一个程序,通过身份证号码判断某人是否是武汉人以及其性别。
package com.swift; public class ID_Where_Male_Test { public static void main(String[] args) { /* * 中 ...
- java中求几个字符串的最大公共子串 使用了比较器Comparator
package com.swift; import java.util.ArrayList; import java.util.Collections; import java.util.Compar ...
- iOS调用WebService接口
首先有几点说在前面 一般,在请求URL的后面带有WSDL字样的需要调用WebService URL样式例子:http://ip:port/navigable/webservice/loginSeric ...
- Protobuf有没有比JSON快5倍?用代码来击破pb性能神话
转 http://www.sohu.com/a/136487507_505779 2017-04-26 07:58 程序设计 /58 /技术 导读:Google 的 Protocol Buffers ...
- RabbitMQ学习(二):Java使用RabbitMQ要点知识
转 https://blog.csdn.net/leixiaotao_java/article/details/78924863 1.maven依赖 <dependency> <g ...
- Linux中让alias设置永久生效的方法详解
Linux中让alias设置永久生效的方法详解 一.问题描述 1.有很多时候我们想要将很多操作作为一个步骤,那么在不作为系统的服务的情况下,别名是我们最好的选择,但是发现别名只能在一次会话中生效,重启 ...
- zuul session 不一致的问题
配置文件: #不加这句话导致session不一致zuul.routes.intelligentsia-authority.sensitiveHeaders = Authorization 过滤器里面 ...
- MyBatis拦截器打印不带问号的完整sql语句方法
/* Preparing: SELECT * FROM tb_user WHERE id = ? AND user_name = ? 目标是打印:SELECT * FROM tb_user WHER ...
- 使用SpringMVC参数传递时,解决get请求时中文乱码的问题
问题描述: 使用SpringMVC参数传递时, 遇到get请求中文信息时,页面应答会显示中文乱码. 解决办法: 一, 我们需要把request.getParameter(“参数名”)获取到的字符串先 ...
- 深入新版BS4源码 探索flex和工程化sass奥秘
你可能已经听说了一个“大新闻”:Bootstrap4 合并了代号为#21389的PR,宣布放弃支持IE9,并默认使用flexbox弹性盒模型.这标志着:1)前端开发全面步入“现代浏览器”的时代进一步来 ...