March of the Penguins
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的更多相关文章
- [POJ 3498] March of the Penguins
March of the Penguins Time Limit: 8000MS Memory Limit: 65536K Total Submissions: 4378 Accepted: ...
- 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 ...
- hdu 2334 March of the Penguins
题意大意 在X,Y坐标系中有N(N<=100)个冰块,有些冰块上有1若干只企鹅,每只企鹅一次最多跳M距离,一个冰块在有Mi个企鹅离开,就会消失,问有哪些冰块可以作为集合点,就是所有企鹅都能成 ...
- poj 3498 March of the Penguins(最大流+拆点)
题目大意:在南极生活着一些企鹅,这些企鹅站在一些冰块上,现在要让这些企鹅都跳到同一个冰块上.但是企鹅有最大的跳跃距离,每只企鹅从冰块上跳走时会给冰块造成损害,因此企鹅跳离每个冰块都有次数限制.找出企鹅 ...
- UVA 12125 March of the Penguins
题意: 给定一些冰块,每个冰块上有一些企鹅,每个冰块有一个可以跳出的次数限制,每个冰块位于一个坐标,现在每个企鹅跳跃力为d,问所有企鹅能否跳到一点上,如果可以输出所有落脚冰块,如果没有方案就打印-1 ...
- UVALive-3972 March of the Penguins (最大流:节点容量)
题目大意:有n个带有裂缝的冰块.已知每个冰块的坐标和已经站在上面的企鹅数目,每当一个企鹅从一个冰块a跳到另一个冰块b上的时候,冰块a上的裂缝便增大一点,还知道每个冰块上最多能被跳跃的次数.所有的企鹅都 ...
- POJ3498:March of the Penguins——题解
最近的题解的故事背景割. 题目: 描述 在靠近南极的某处,一些企鹅站在许多漂浮的冰块上.由于企鹅是群居动物,所以它们想要聚集到一起,在同一个冰块上.企鹅们不想把自己的身体弄湿,所以它们在冰块之间跳跃, ...
- UVALIVE 3972 March of the Penguins
最大流建图比较容易第一次Dicnc抄了下别人的版 存一下以后方便查 #include <map> #include <set> #include <list> #i ...
随机推荐
- LayoutInflater的inflate函数用法
LayoutInflater作用是将layout的xml布局文件实例化为View类对象. 获取LayoutInflater的方法有如下三种: LayoutInflater inflater=(Layo ...
- react native web
http://rawgit.com/taobaofed/react-web/master/pages/uiexplorer.html#/scene_1?_k=7vm99j
- HTTP基础:URL格式、 HTTP请求、响应、消息
HTTP URL 格式: http://host[:port][abs_path] 其中http表示要通过HTTP协议来定位网络资源. host表示合法的Internet主机域名或IP地址(以点分十进 ...
- CentOS7系统下搭建Jenkins环境
1. 安装JDK yum -y install java 2.安装Ant 添加JPackage源 yum -y install wget wget http://www.jpackage.org/jp ...
- phpcms 换域名
修改/caches/configs/system.php里面所有和域名有关的,把以前的老域名修改为新域名就可以了. 进行后台设置->站点管理 对相应的站点的域名进行修改. 更新系统缓存.点击 ...
- 规划收发你的邮件,使用qq邮箱接收阿里云企业邮邮件
使用qq邮箱接收阿里企业邮 首先管理员开通企业邮后会发来激活短信 根据短信提示打开https://qiye.aliyun.com企业邮登陆地址 使用短信提供的密码登陆邮箱 首次登陆时会让我们重设密码 ...
- [功能帮助类] C#RandomHelper随机数,随机字符,可限制范围-帮助类 (转载)
点击下载 RandomHelper.rar 主要功能如下 .生成一个指定范围的随机整数,该随机数范围包括最小值,但不包括最大值 .生成一个0.0到1.0的随机小数 .对一个数组进行随机排序 . 一:随 ...
- 额定能量不得超过160Wh, 等同是多少mAh电池容量?
额定能量不得超过160Wh, 等同是多少mAh电池容量?行动电源容量标示, 正确应该是用Whr(Wh)瓦特小时来标示, 不过坊间标榜行动电源的容量通常是用xx000mAhWHr瓦特小时, 即是行动电源 ...
- 菜鸟日记之JSP1
JSP全名为Java Server Pages,中文名叫java服务器页面,其根本是一个简化的Servlet设计,它 是由Sun Microsyste ...
- 祭奠一年前写 Direct2D demo
一年前, 用Direct2D实现了不怎么样的UI库. 用不怎么样的UI库实现了这个Demo. 当时放进某群共享, 以此装逼. 今天无意中翻出来, 解压, 什么都没变, 还是压缩前的模样. 不经意看见被 ...