[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上的裂缝便增大一点,还知道每个冰块上最多能被跳跃的次数.所有的企鹅都 ...
随机推荐
- mysql 错误- 磁盘空间不足,
mysql 磁盘空间不足错误 磁盘空间满了, 写不进去了. :: mysqld_safe Starting mysqld daemon with databases from /alidata/ser ...
- angular入门系列教程1
主题: 一个能够跑起来的页面,神奇的效果,无需一样JS代码! 效果图: 细节: 当然,这里甚至连登陆都没做,只是看到神奇的当输入用户名或者密码的时候,下面的预览区域也会有相应的更改.没有一行的JS代码 ...
- 【DP】BZOJ 1260: [CQOI2007]涂色paint
1260: [CQOI2007]涂色paint Time Limit: 30 Sec Memory Limit: 64 MBSubmit: 893 Solved: 540[Submit][Stat ...
- 【单调栈】Bzoj 1012: 最大数maxnumber
1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec Memory Limit: 162 MBSubmit: 6255 Solved: 2676[Submi ...
- 【BZOJ】【1115】【POI2009】石子游戏KAM
博弈论 这个题……一看就觉得很捉急啊= =肿么办? 灵光一现:差分一下~ 那么我们看一下差分以后,从第 i 堆中拿走 k 个石子变成了:a[i]-=k; a[i+1]+=k; 嗯这就转化成了阶梯博弈! ...
- [转载]C#中的WebBrowser控件的使用
http://www.cnblogs.com/txw1958/archive/2012/09/24/CSharp-WebBrowser.html
- soft particles
http://developer.download.nvidia.com/whitepapers/2007/SDK10/SoftParticles_hi.pdf nvdia ------------- ...
- web配置详解
1.启动一个WEB项目的时候,WEB容器会去读取它的配置文件web.xml,读取<listener>和<context-param>两个结点. 2.紧急着,容创建一个Servl ...
- Unity3D Script Execution Order ——Question
我 知道 Monobehaviour 上的 那些 event functions 是 在主线程 中 按 顺序调用的.这点从Manual/ExecutionOrder.html 上的 一张图就可以看出来 ...
- Android 使用系统的Activity播放音频文件 intent
Intent intent = new Intent(); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setAction(Inten ...