poj3498:http://poj.org/problem?id=3498

题意:某个冰块上有a只企鹅,总共可以跳出去b只,问是否可能所有的企鹅都跳到某一块冰块上,输出所有的可能的冰块的编号。

由于每个点只能跳出去m只企鹅,所以要拆点假如不拆点,一个点到另一个点可能会跳多于m只企鹅通过拆点后u->u'间的容量来完成题目的要求(对点的一些限制)

建图:i->i+n 容量为m i+n->j容量为INF新建源点s,s->i的容量为i点企鹅的个数然后枚举汇点求最大流就可以判断某个点是否符合条件

 #include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cmath>
#define INF 100000000
using namespace std;
const int N=;
const int M=;
struct Node{
int v;
int f;
int next;
}edge[M];
int n,m,u,v,cnt,sx,ex;
int head[N],pre[N];
int ans[N],top,val[N];
void init(){
cnt=;
memset(head,-,sizeof(head));
}
void add(int u,int v,int w){
edge[cnt].v=v;
edge[cnt].f=w;
edge[cnt].next=head[u];
head[u]=cnt++;
edge[cnt].f=;
edge[cnt].v=u;
edge[cnt].next=head[v];
head[v]=cnt++;
}
bool BFS(){
memset(pre,,sizeof(pre));
pre[sx]=;
queue<int>Q;
Q.push(sx);
while(!Q.empty()){
int d=Q.front();
Q.pop();
for(int i=head[d];i!=-;i=edge[i].next ){
if(edge[i].f&&!pre[edge[i].v]){
pre[edge[i].v]=pre[d]+;
Q.push(edge[i].v);
}
}
}
return pre[ex]>;
}
int dinic(int flow,int ps){
int f=flow;
if(ps==ex)return f;
for(int i=head[ps];i!=-;i=edge[i].next){
if(edge[i].f&&pre[edge[i].v]==pre[ps]+){
int a=edge[i].f;
int t=dinic(min(a,flow),edge[i].v);
edge[i].f-=t;
edge[i^].f+=t;
flow-=t;
if(flow<=)break;
} }
if(f-flow<=)pre[ps]=-;
return f-flow;
}
int solve(){
int sum=;
while(BFS())
sum+=dinic(INF,sx);
return sum;
}
double d;
int xx[N],yy[N],num[N];
int main(){
int T,sum;
scanf("%d",&T);
while(T--) {
sum=;
scanf("%d %lf",&n,&d);
for(int i=;i<=n;i++){
scanf("%d%d%d%d",&xx[i],&yy[i],&val[i],&num[i]);
sum+=val[i];
}
top=;
for(int i=;i<=n;i++){
init();
for(int j=;j<=n;j++){
if(j==i)continue;
add(,j,val[j]);
add(j,j+n,num[j]);
}
for(int j=;j<=n;j++){
for(int k=;k<=n;k++){
if(k==j)continue;
if(j==i)continue;
double temp=sqrt((xx[j]-xx[k])*1.0*(xx[j]-xx[k])+(yy[j]-yy[k])*1.0*(yy[j]-yy[k]));
if(temp<=d){
add(j+n,k,INF);
}
}
}
add(i,*n+,INF);
sx=,ex=*n+;
if(solve()==sum-val[i]){
ans[++top]=i;
} }
if(top<)printf("-1\n");
else{
sort(ans+,ans+top+);
for(int i=;i<top;i++)
printf("%d ",ans[i]-);
printf("%d\n",ans[top]-);
}
}
return ;
}

March of the Penguins的更多相关文章

  1. [POJ 3498] March of the Penguins

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

  2. poj 3498 March of the Penguins(拆点+枚举汇点 最大流)

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

  3. POJ 3498 March of the Penguins(网络最大流)

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

  4. hdu 2334 March of the Penguins

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

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

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

  6. UVA 12125 March of the Penguins

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

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

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

  8. POJ3498:March of the Penguins——题解

    最近的题解的故事背景割. 题目: 描述 在靠近南极的某处,一些企鹅站在许多漂浮的冰块上.由于企鹅是群居动物,所以它们想要聚集到一起,在同一个冰块上.企鹅们不想把自己的身体弄湿,所以它们在冰块之间跳跃, ...

  9. UVALIVE 3972 March of the Penguins

    最大流建图比较容易第一次Dicnc抄了下别人的版 存一下以后方便查 #include <map> #include <set> #include <list> #i ...

随机推荐

  1. TCP/IP 编程

    http://www.cnblogs.com/ggjucheng/archive/2012/08/18/2645324.html

  2. android开发之国际化

    国际化,听起来高大上,做起来很简单. 我们来实现一个简单的效果,让应用根据系统的语言来做不同的显示,假如android系统默认是英语,应用就以英文的形式显示,如果android系统默认是中文,则应用就 ...

  3. android 6.0获取 WRITE_SETTINGS 权限

    android 6.0上只写在AndroidManifest中是不行的,还必须手动打开才行 private void setBrightnessMode(Context context, int mo ...

  4. Python学习入门教程,字符串函数扩充详解

    因有用户反映,在基础文章对字符串函数的讲解太过少,故写一篇文章详细讲解一下常用字符串函数.本文章是对:程序员带你十天快速入门Python,玩转电脑软件开发(三)中字符串函数的详解与扩充. 如果您想学习 ...

  5. volatile用处说明

      在JDK1.2之前,Java的内存模型实现总是从主存(即共享内存)读取变量,是不需要进行特别的注意的.而随着JVM的成熟和优化,现在在多线程环境下volatile关键字的使用变得非常重要. 在当前 ...

  6. mvc 路由 使用

    url 特性路由: 特性路由可以在 controller和action里面自定义路由规则  这种方式比较灵活  缺点就是不能很好的统一管理url 注册特性路由: public static void ...

  7. [GDI+] C# ImageClass帮助类教程与源码下载 (转载)

    点击下载 ImageClass.rar 功能如下图片 主要功能有:缩略图片,图片水印,文字水印,调整光暗,反色处理,浮雕处理,拉伸处理,左右翻转,上下翻转,压缩图片,图片灰度化,转换为黑白图片,获取图 ...

  8. CSS 尺寸 (Dimension)

    CSS 尺寸 (Dimension) 属性允许你控制元素的高度和宽度.同样,它允许你增加行间距. 更多实例 设置元素的高度 这个例子演示了如何设置不同元素的高度. 使用百分比设置图像的高度 这个例子演 ...

  9. MySQL 时间戳(Timestamp)函数

    1. MySQL 获得当前时间戳函数:current_timestamp, current_timestamp() mysql> select current_timestamp, curren ...

  10. 《玩转shutdown》-linux命令五分钟系列之十三

    1 我想立即关机! $shutdown -h now 2 我想立即重启 $shutdown -r now 3 我想在23:30分准时关机 $shutdown -h 23:30 4 我想在15分钟后关机 ...