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 xiyini 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 ≤ xiyi ≤ 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的更多相关文章

  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(网络最大流)

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

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

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

  4. poj 3498 最大流

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

  5. March of the Penguins

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

  6. poj 3498(最大流+拆点)

    题目链接:http://poj.org/problem?id=3498 思路:首先设一个超级源点,将源点与各地相连,边容量为各点目前的企鹅数量,然后就是对每个冰块i进行拆点了(i,i+n),边容量为能 ...

  7. hdu 2334 March of the Penguins

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

  8. UVA 12125 March of the Penguins

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

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

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

随机推荐

  1. 邻结矩阵的建立和 BFS,DFS;;

    邻结矩阵比较简单,, 它的BFS,DFS, 两种遍历也比较简单,一个用队列, 一个用数组即可!!!但是邻接矩阵极其浪费空间,尤其是当它是一个稀疏矩阵的时候!!!-------------------- ...

  2. oracle 建立主键与索引【转】

    此文转自:http://blog.sina.com.cn/s/blog_439f80c4010094n1.html 创建主键: alter table T add primary key (V) T是 ...

  3. switch..case函数的基础使用一

    基本作用:switch中的参数与case的值进行比对,相等则进入case. JDK1.7 switch支持int.Integer.String类型 package com.my.test; impor ...

  4. 【BZOJ】【2820】YY的GCD

    莫比乌斯反演 PoPoQQQ讲义第二题. 暴力枚举每个质数,然后去更新它的倍数即可,那个g[x]看不懂就算了…… 为什么去掉了一个memset就不T了→_→…… /****************** ...

  5. C# 生成MD5编码方法(不同位数)

    /// <summary>          /// </summary>          /// <param name="strSource"& ...

  6. C# 正则表达式 匹配IP地址

    \b(([01]?\d?\d|2[0-4]\d|25[0-5])\.){3}([01]?\d?\d|2[0-4]\d|25[0-5])\b

  7. 2-Highcharts曲线图之折线图

    示例图片,在网上下载一张图片如图:其中数据自定义 引入上节模版配置  在script标签中写代码:具体代码如下   信息将在代码中解释. 分析:“五省收益趋势”是标题: x坐标为[2011年-2016 ...

  8. 能"干掉"苹果的中国"黑客"

    他是全球发现苹果漏洞最多的人,他曾穷的住在小黑屋,他经常接到国家安全部门的电话,他差点堵住周鸿祎的路,他是谁? 无名英雄 我们最终还是没有见到吴石本人,即便他的生意合伙人刘盛(化名)已经应承了帮我们牵 ...

  9. uva 11029

    看了别人的解法 发现了 modf 这个函数 取小数部分 /*********************************************************************** ...

  10. POJ2151Check the difficulty of problems

    题意 : 举办一次比赛不容易,为了不让题目太难,举办方往往希望能够讲出的题目满足两点,1是所有的队伍都至少能够解出一个题目,2是冠军队至少能解出确定数量的题目,最后让你求的是每个队伍至少解出一道题并且 ...