hdu 2334 March of the Penguins
题意大意
在X,Y坐标系中有N(N<=100)个冰块,有些冰块上有1若干只企鹅,每只企鹅一次最多跳M距离,一个冰块在有Mi个企鹅离开,就会消失,问有哪些冰块可以作为集合点,就是所有企鹅都能成功到这个冰块上来
题目分析
枚举点作为结束点,由于每个点有出企鹅的限制,用拆点来解决,一个点拆成"起点"和"终点",“起点"到"终点"的流量为最大离开企鹅数,而超级源点与每个点的"起点"做边,容量为其企鹅的数量,再根据各之间的关系做边,最后跑最 大流判断是否=总企鹅数
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#define maxn 5000
#define MAXN 2005
#define MAXM 20000005
#define INF 100000000
#define oo 1000000007
using namespace std; struct Dinic
{
struct node
{
int x,y,c,next;
}line[MAXM];
int Lnum,_next[MAXN],dis[MAXN],dp[MAXN];
bool inqueue[MAXN];
void initial(int n)
{
for (int i=;i<=n;i++) _next[i]=-;
Lnum=-;
}
void addline(int x,int y,int c)
{
line[++Lnum].next=_next[x],_next[x]=Lnum;
line[Lnum].x=x,line[Lnum].y=y,line[Lnum].c=c;
line[++Lnum].next=_next[y],_next[y]=Lnum;
line[Lnum].x=y,line[Lnum].y=x,line[Lnum].c=;
}
bool BFS(int s,int e)
{
queue<int> Q;
while (!Q.empty()) Q.pop();
memset(dis,,sizeof(dis));
dis[s]=,Q.push(s);
while (!Q.empty())
{
int h,k;
h=Q.front(),Q.pop();
if (h==e) return dis[e];
for (k=_next[h];k!=-;k=line[k].next)
if (line[k].c && !dis[line[k].y])
dis[line[k].y]=dis[h]+,Q.push(line[k].y);
}
return false;
}
int dfs(int x,int flow,int e)
{
if (x==e) return flow;
int temp,cost=;
for (int k=_next[x];k!=-;k=line[k].next)
if (line[k].c && dis[line[k].y]==dis[x]+)
{
temp=dfs(line[k].y,min(flow-cost,line[k].c),e);
if (temp)
{
line[k].c-=temp,line[k^].c+=temp;
cost+=temp;
if (flow==cost) return cost;
}else dis[line[k].y]=-;
}
return cost;
}
int MaxFlow(int s,int e)
{
int MaxFlow=;
while (BFS(s,e)) MaxFlow+=dfs(s,oo,e);
return MaxFlow;
}
}T;
struct Point
{
int x,y,n,m;
};
Point p[maxn]; int dist(int s,int t,double dd)
{
return (p[s].x-p[t].x)*(p[s].x-p[t].x)+(p[s].y-p[t].y)*(p[s].y-p[t].y)<=dd;
}
int vist[maxn][maxn];
bool judge(int e,int n,int sum)
{
int i,j,s=n*+;
T.initial(n*+);
for (i=;i<n;i++) T.addline(s,i<<,p[i].n),T.addline(i<<,i<<|,p[i].m);
for (i=;i<n;i++)
for (j=;j<n;j++)
if (i!=j && vist[i][j])
T.addline(i<<|,j<<,oo);
return T.MaxFlow(s,e)==sum;
}
int main()
{
int t,n;
double d;
scanf("%d",&t);
while(t--)
{
scanf("%d%lf",&n,&d);
d=d*d;
int sum=;
for(int i=;i<n;i++)
scanf("%d %d %d %d",&p[i].x,&p[i].y,&p[i].n,&p[i].m),sum+=p[i].n;
//memset(vist,0,sizeof(vist));
for(int i=;i<n;i++)
for(int j=;j<n;j++)
{
if((p[i].x-p[j].x)*(p[i].x-p[j].x)+(p[i].y-p[j].y)*(p[i].y-p[j].y)<=d)
vist[i][j]=;
else
vist[i][j]=;
} int flag=;
for(int i=;i<n;i++)
{
if(judge(i*,n,sum))
{
flag++;
if(flag==)
printf("%d",i);
else
printf(" %d",i);
}
}
if(flag==)
printf("-1");
printf("\n");
}
return ;
}
hdu 2334 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 ...
- March of the Penguins
poj3498:http://poj.org/problem?id=3498 题意:某个冰块上有a只企鹅,总共可以跳出去b只,问是否可能所有的企鹅都跳到某一块冰块上,输出所有的可能的冰块的编号. 由于 ...
- 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 ...
随机推荐
- 如何在 Linux 中整理磁盘碎片
有一个神话是 linux 的磁盘从来不需要整理碎片.在大多数情况下这是真的,大多数因为是使用的是优秀的日志文件系统(ext3.4等等)来处理文件系统.然而,在一些特殊情况下,碎片仍旧会产生.如果正巧发 ...
- hihocoder 1138 Islands Travel dijkstra+heap 难度:2
http://hihocoder.com/problemset/problem/1138 很久不用最短路,几乎连基本性质也忘了,结果这道题就是某些最短路算法空间复杂度是o(n) 这里总结四种算法 算法 ...
- 启动项目报错Error: listen EADDRINUSE
我在使用elasticsearch的kibana插件时候,有一次启动,遇到这个错误: Error: listen EADDRINUSE 它的意思是,端口5601被其他进程占用. 故而,需要kill掉那 ...
- C++定义构造函数必须使用初始化列表的场合
明其理,而知其然也. 先给理论.1. 初始化 != 赋值. a.初始化代表为变量分配内存. 变量在其定义处被编译器初始化(编译时). 在函数中, 函数参数初始化发生在函数调用时(运行时). b.赋值代 ...
- [转载]Matrix类的使用
2013-12-18 11:31:00 转载自: http://www.cnblogs.com/mmy0925/archive/2013/01/22/2871009.html 在Android中,对图 ...
- ImageLoder配置以及使用(个人阅读使用)
http://blog.csdn.net/vipzjyno1/article/details/23206387 在gradle添加: compile 'com.nostra13.universalim ...
- JS 跨域问题浅析及解决方法优缺点对比(转)
1.所谓 JS 跨域问题,是指在一个域下的页面中通过js访问另一个不同域下 的数据对象, 出于安全性考 虑,几乎所有浏览器都不允许这种跨域访问,这就导致在一些ajax应用中, 使用跨域的web ser ...
- FSMC stm32
1.FSMC机制 FSMC(Flexihie Static Memory Controller,可变静态存储控制器)是STM32系列中内部集成256 KB以上FlaSh,后缀为xC.xD和xE的高存储 ...
- Sublime Text2 jedi插件离线安装
1.Sublime Text2 下载安装 2.下载jedi gitbub上的,https://github.com/srusskih/SublimeJEDI 3.打开sublime后,组合键“c ...
- mysql存储过程笔记
http://blog.csdn.net/wangchao0605/article/details/5935988 基本语法 创建存储过程 create procedure sp_name()begi ...