题意:

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

分析:

  很显然的最大流问题。把每个冰块x拆成x和x',连x->x'流量为跳出的次数限制。枚举落脚冰块建图跑最大流即可

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
using namespace std;
const int maxn = 202 + 10;
const int INF = 1000000000;
struct Edge
{
int from,to,cap,flow;
};
struct Dinic
{
int n,m,s,t;
vector<Edge>edges;
vector<int>G[maxn];
bool vis[maxn];
int d[maxn];
int cur[maxn];
void clearall(int n)
{
for(int i=0;i<n;i++)
G[i].clear();
edges.clear();
}
void clearflow()
{
for(int i=0;i<edges.size();i++)
edges[i].flow=0;
}
void addedge(int from,int to,int cap)
{
edges.push_back((Edge){from,to,cap,0});
edges.push_back((Edge){to,from,0,0});
m=edges.size();
G[from].push_back(m-2);
G[to].push_back(m-1);
}
bool bfs()
{
memset(vis,0,sizeof(vis));
queue<int>Q;
Q.push(s);
vis[s]=1;
d[s]=0;
while(!Q.empty())
{
int x=Q.front();
Q.pop();
for(int i=0;i<G[x].size();i++)
{
Edge& e=edges[G[x][i]];
if(!vis[e.to]&&e.cap>e.flow)
{
vis[e.to]=1;
d[e.to]=d[x]+1;
Q.push(e.to);
}
}
}
return vis[t];
}
int dfs(int x,int a)
{
if(x==t||a==0)
{
return a;
}
int flow=0,f;
for(int& i=cur[x];i<G[x].size();i++)
{
Edge& e=edges[G[x][i]];
if(d[x]+1==d[e.to]&&(f=dfs(e.to,min(a,e.cap-e.flow)))>0)
{
e.flow+=f;
edges[G[x][i]^1].flow -= f;
flow+=f;
a-=f;
if(a==0)
break;
}
}
return flow;
}
int maxflow(int s,int t)
{
this->s=s;
this->t=t;
int flow=0;
//cout<<2<<endl;
while(bfs())
{
memset(cur,0,sizeof(cur));
flow+=dfs(s,INF);
}
//cout<<3<<endl;
return flow;
}
};
struct Node
{
int x,y,num;
}p[maxn];
Dinic solver;
double dis(Node a,Node b)
{
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
vector<int>ans;
int main()
{
int t,n,total;
double D;
scanf("%d",&t);
while(t--)
{
scanf("%d%lf",&n,&D);
solver.clearall(2*n+1);
int s1=0;
total=0;
D=D*D;
for(int i=1;i<=n;i++)
{
int x,y,ni,cap;
scanf("%d%d%d%d",&x,&y,&ni,&cap);
p[i].x=x;p[i].y=y;p[i].num=ni;
total+=ni;
solver.addedge(s1,i,ni);
solver.addedge(i,i+n,cap);
}
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(i != j && D-dis(p[i],p[j])> 1e-6)
{
solver.addedge(i+n,j,INF);
}
int sum=0;
ans.clear();
//cout<<1<<endl;
for(int i=1;i<=n;i++)
{
solver.clearflow();
if(solver.maxflow(s1,i)==total)
{
ans.push_back(i);
sum++;
}
}
//cout<<sum<<endl;
if(sum==0)
printf("-1\n");
else
{
for(int i=0;i<ans.size()-1;i++)
printf("%d ",ans[i]-1);
printf("%d\n",ans[ans.size()-1]-1);
}
}
}

输入:

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

UVA 12125 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. March of the Penguins

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

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

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

  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. Android的Fragment中onActivityResult不被调用的解决方案

    常见的,我们会在FragmentActivity中嵌套一层Fragment使用,甚至两次或多层Fragment嵌套使用.这个时候,在第二级或者更深级别的Fragment调用startActivityF ...

  2. (转)创建和查看Javadoc文档

    原地址:http://jinnaxu-tju-edu-cn.iteye.com/blog/667177 Javadoc是Sun公司提供的一个技术,它从程序源代码中抽取类.方法.成员等注释形成一个和源代 ...

  3. JDK动态代理例子

    JDK动态代理的代理类必须实现于接口.如果要代理类,则使用CGLIB代理. 先定义一个接口: public interface Character { public void show(); } 接着 ...

  4. CSS3动画之旋转魔方盒

    步骤: 1.大盒子里盛放六个子盒子代表立方体的6个面: 2.子盒子开启3d效果  transform-style:preserve-3d; 3.上下面沿X轴旋转90度,一个上移盒子一半高,一个下移盒子 ...

  5. Spring连接MySQL、Oracle和SQL Server的数据库运动连接属性

    在配置文件applicationContext.xml设置如下:<?xml version="1.0" encoding="UTF-8"?>< ...

  6. flash播放器遮挡页面中元素问题解决

    今天在做一个包含Flash播放器的页面弹出效果时发现Flash播放器总是跑到页面最上层,发现这个问题与Flash的”wmode”属性有关,至于该元素详细此处不做记录,解决办法如下: IE:加入参数:& ...

  7. Python中def的用法

    def定义了一个模块的变量,或者说是类的变量.它本身是一个函数对象.属于对象的函数,就是对象的属性. def func():    return 2print func() # 1func = 5pr ...

  8. Struts2+JQuery+JSON实现异步交互

    1.环境 jquery:jquery-1.9.0.min.js struts2:基本包就不说了,就说说应用json的包,主要有struts2-json-plugin-2.3.8.jar json:js ...

  9. hash算法-time33算法

    http://my.oschina.net/freegeek/blog/325531 http://www.cnblogs.com/napoleon_liu/articles/1911571.html ...

  10. BZOJ 3529 数表(莫比乌斯反演)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3529 思路:令F(i)为i的约数和, 1<=x<=n,1<=y<=m G(i ...