[POJ 3498] March of the Penguins
| Time Limit: 8000MS | Memory Limit: 65536K | |
| Total Submissions: 4378 | Accepted: 1988 |
Description
Somewhere near the south pole, a number of penguins are standing on a number of ice floes. Being social animals, the penguins would like to get together, all on the same floe. The penguins do not want to get wet, so they have use their limited jump distance to get together by jumping from piece to piece. However, temperatures have been high lately, and the floes are showing cracks, and they get damaged further by the force needed to jump to another floe. Fortunately the penguins are real experts on cracking ice floes, and know exactly how many times a penguin can jump off each floe before it disintegrates and disappears. Landing on an ice floe does not damage it. You have to help the penguins find all floes where they can meet.

A sample layout of ice floes with 3 penguins on them.
Input
On the first line one positive number: the number of testcases, at most 100. After that per testcase:
One line with the integer N (1 ≤ N ≤ 100) and a floating-point number D (0 ≤ D ≤ 100 000), denoting the number of ice pieces and the maximum distance a penguin can jump.
N lines, each line containing xi, yi, ni and mi, denoting for each ice piece its X and Y coordinate, the number of penguins on it and the maximum number of times a penguin can jump off this piece before it disappears (−10 000 ≤ xi, yi ≤ 10 000, 0 ≤ ni ≤ 10, 1 ≤ mi ≤ 200).
Output
Per testcase:
- One line containing a space-separated list of 0-based indices of the pieces on which all penguins can meet. If no such piece exists, output a line with the single number −1.
Sample Input
2
5 3.5
1 1 1 1
2 3 0 1
3 5 1 1
5 1 1 1
5 4 0 1
3 1.1
-1 0 5 10
0 0 3 9
2 0 1 1
Sample Output
1 2 4
-1
经典最大流、- -
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
#define INF 0x3f3f3f3f
#define N 1010
#define M 100010 struct Edge
{
int to,next,val;
}edge[M];
int tot;
int head[N]; int pre[N];
int cur[N];
int gap[N];
int dep[N]; void init()
{
tot=;
memset(head,-,sizeof(head));
}
void add(int u,int v,int w,int rw=)
{
edge[tot].to=v;
edge[tot].val=w;
edge[tot].next=head[u];
head[u]=tot++;
edge[tot].to=u;
edge[tot].val=rw;
edge[tot].next=head[v];
head[v]=tot++;
}
int SAP(int src,int des,int n)
{
memset(dep,,sizeof(dep));
memset(gap,,sizeof(gap));
memcpy(cur,head,sizeof(head)); int u=pre[src]=src;
int maxflow=,aug=-;
gap[]=n; while(dep[src]<n){
loop:
for(int &i=cur[u];i!=-;i=edge[i].next){
int v=edge[i].to;
if(edge[i].val && dep[u]==dep[v]+){
aug==-?(aug=edge[i].val):(aug=min(aug,edge[i].val));
pre[v]=u;
u=v;
if(v==des){
maxflow+=aug;
for(u=pre[v];v!=src;v=u,u=pre[u]){
edge[cur[u]].val-=aug;
edge[cur[u]^].val+=aug;
}
aug=-;
}
goto loop;
}
}
int Min=n;
for(int i=head[u];i!=-;i=edge[i].next){
int v=edge[i].to;
if(edge[i].val && Min>dep[v]){
cur[u]=i;
Min=dep[v];
}
}
if(--gap[dep[u]]==) break;
dep[u]=Min+;
gap[dep[u]]++;
u=pre[u];
}
return maxflow;
} int n,sum,k1[N],k2[N];
double d,x[N],y[N]; double dis(int i,int j)
{
return sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
init();
sum=;
scanf("%d%lf",&n,&d);
for(int i=;i<=n;i++){
scanf("%lf%lf%d%d",&x[i],&y[i],&k1[i],&k2[i]);
sum+=k1[i];
} for(int i=;i<=n;i++) add(,i,k1[i]);
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
if(i!=j && dis(i,j)<=d){
add(i+n,j,INF);
}
}
}
for(int i=;i<=n;i++) add(i,i+n,k2[i]); int ans[N],ansd=;
for(int i=;i<=n;i++){
int t=SAP(,i,*n+);
if(t==sum) ans[++ansd]=i;
for(int j=;j<tot;j+=){
edge[j].val+=edge[j^].val,edge[j^].val=;
}
}
for(int i=;i<=ansd;i++){
if(i==ansd) printf("%d\n",ans[i]-);
else printf("%d ",ans[i]-);
}
if(!ansd) printf("-1\n");
}
return ;
}
[POJ 3498] 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(网络最大流)
Description Somewhere near the south pole, a number of penguins are standing on a number of ice floe ...
- poj 3498 March of the Penguins(最大流+拆点)
题目大意:在南极生活着一些企鹅,这些企鹅站在一些冰块上,现在要让这些企鹅都跳到同一个冰块上.但是企鹅有最大的跳跃距离,每只企鹅从冰块上跳走时会给冰块造成损害,因此企鹅跳离每个冰块都有次数限制.找出企鹅 ...
- poj 3498 最大流
March of the Penguins Time Limit: 8000MS Memory Limit: 65536K Total Submissions: 4809 Accepted: ...
- March of the Penguins
poj3498:http://poj.org/problem?id=3498 题意:某个冰块上有a只企鹅,总共可以跳出去b只,问是否可能所有的企鹅都跳到某一块冰块上,输出所有的可能的冰块的编号. 由于 ...
- poj 3498(最大流+拆点)
题目链接:http://poj.org/problem?id=3498 思路:首先设一个超级源点,将源点与各地相连,边容量为各点目前的企鹅数量,然后就是对每个冰块i进行拆点了(i,i+n),边容量为能 ...
- hdu 2334 March of the Penguins
题意大意 在X,Y坐标系中有N(N<=100)个冰块,有些冰块上有1若干只企鹅,每只企鹅一次最多跳M距离,一个冰块在有Mi个企鹅离开,就会消失,问有哪些冰块可以作为集合点,就是所有企鹅都能成 ...
- UVA 12125 March of the Penguins
题意: 给定一些冰块,每个冰块上有一些企鹅,每个冰块有一个可以跳出的次数限制,每个冰块位于一个坐标,现在每个企鹅跳跃力为d,问所有企鹅能否跳到一点上,如果可以输出所有落脚冰块,如果没有方案就打印-1 ...
- UVALive-3972 March of the Penguins (最大流:节点容量)
题目大意:有n个带有裂缝的冰块.已知每个冰块的坐标和已经站在上面的企鹅数目,每当一个企鹅从一个冰块a跳到另一个冰块b上的时候,冰块a上的裂缝便增大一点,还知道每个冰块上最多能被跳跃的次数.所有的企鹅都 ...
随机推荐
- 原型prototype -- 深入理解javascript
/* 原型Prototype */ //一.原型 //原型使用一 var calculator = function (dlg, tax) { this.dlg = dlg; this.tax = t ...
- knockoutjs select onchange 下拉级联
1.绑定数据源 <select name="" class="xlb02" data-bind="options: $root.dataSour ...
- 3139:[HNOI2013]比赛 - BZOJ
题目描述 Description 沫沫非常喜欢看足球赛,但因为沉迷于射箭游戏,错过了最近的一次足球联赛.此次联赛共N只队伍参加,比赛规则如下: (1) 每两支球队之间踢一场比赛. (2) 若平局,两支 ...
- linux 下安装 nginx
安装nginx版本为1.7.5 一.下载nginx 官方地址:http://www.nginx.org/ 下载地址:http://nginx.org/download/ Nginx官网提供了三个类型的 ...
- Java---算法---插入排序
/** * 插入排序(升序) * * @param array */ public static void insertSort(int[] array) { int j = 0; // 下标从1开始 ...
- AnkhSVN 安装
为 visual Studio 2013 添加 AnkhSVN 步骤 到 https://ankhsvn.open.collab.net/downloads 下载 2.6x或以上 安装 AnkhSvn ...
- ReplicaManager之DelayedOperation
DelayedOperation包括两种:DelayedFetch和DelayedProduce,它们的存在是由Kafka Protocol决定的,而Kafka Protocol是由实际需求决定的…… ...
- XML注入介绍--XXE,XEE,xpath等
XML注入指在请求的XML中插入攻击利用代码.根据不同的场景,可能会形成以下的漏洞形式: (1)XEE ----xml entity xpansion(xml实体膨胀,用于dos) 具体介绍:http ...
- crontab 指定执行用户
linux下可以通过配置crontab来定时执行任务,执行体可以是一条系统命令或自己写的一个脚本,同时可以指派用户来执行.配置crontab有两种方法.方法1.使用crontab命令,例如添加一个新的 ...
- POJ3009Curling 2.0
http://poj.org/problem?id=3009 题意 : 迷宫升级版,也是m*n的迷宫,0是可以走的,1是阻塞,2是初始点,3是目标位置,这个的阻塞是可以消除的,就是说只要石头撞到阻塞, ...