[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上的裂缝便增大一点,还知道每个冰块上最多能被跳跃的次数.所有的企鹅都 ...
随机推荐
- [C#]Linq To Xml 介绍- 转
LINQ to XML 类概述 LINQ to XML 旨在使 XML 名称尽可能简单. XAttribute 类 XAttribute 表示一个 XML 属性. XCData 类 XCDat ...
- C# 越来越复杂了
自从三年前来到现在的公司以后,基本上不怎么使用.NET进行开发了.但最近因为公司有个CRM的项目,所以只有重新检起.NET进行开发. 因为近3年没有搞.NET的开发了,因此也不敢乱整个框架,在看了一周 ...
- 解决Ubuntu开机自动挂载硬盘回收站不可用等权限问题
1.修改fstab sudo gedit /etc/fstab 2.添加如下代码 #Entry for /dev/sdb7 : UUID=78A675EB46D703C4 /media/anseey/ ...
- 如何将jsp中<input>设为只读
将一个input变为只读,可以使用 readonly 属性 和 disabled 属性. 用disabled 属性时,文字显示为灰色. 下面的两种方法都是可以的: <input id =&q ...
- VC6.0环境安装STLport-5.2.1
今天安装STLport,网上搜资料安装好久,都不行,因为STLport 的版本不对,我这是STLport-5.2.1新版本. (注意:下面的步骤都在一个cmd里操作,很简单的原因:环境变量啊) 1.首 ...
- 如何实现Windows Phone代码与Unity相互通信(事件方式)
源地址:http://www.cnblogs.com/petto/p/3909063.html 一些废话 昨天写一篇今天写一篇.不是我闲的蛋疼,是今天一天碰到了好几个恼人的问题,浪费一天时间搞定.本文 ...
- gcd 最大公约数 模版!
1: #define ll long long ll gcd(ll a,ll b) { ) { return b; }else { return gcd(b % a,a); } } 2: int64 ...
- 2013 ACM-ICPC长沙赛区全国邀请赛——A So Easy!
这题在比赛的时候不知道怎么做,后来看了别人的解题报告,才知道公式sn=(a+sqrt(b))^n+(a-sqrt(b))^n; 具体推导 #include<iostream> #inclu ...
- Java 获取amr音频格式的音频长度
import java.io.File; import java.io.IOException; import java.io.RandomAccessFile; public class GetAm ...
- java 多线程 CountDownLatch用法
CountDownLatch,一个同步辅助类,在完成一组正在其他线程中执行的操作之前,它允许一个或多个线程一直等待. 主要方法 public CountDownLatch(int count); pu ...