UVALIVE 3972 March of the Penguins
最大流建图比较容易第一次Dicnc抄了下别人的版
存一下以后方便查
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b) {return a % b == ? b : gcd(b, a % b);}
#define MAXN 220
const int INF = 0x3f3f3f3f ;
struct node
{
int u,v,next;
int cap,flow;
}edge[MAXN * MAXN * ];
struct Dicnc
{
int source,target;
bool vis[MAXN];
int d[MAXN],cur[MAXN],head[MAXN],cnt;
int n;
void init(int x)
{
memset(head,-,sizeof(head));
cnt = ;
n = x;
}
void addedge(int u ,int v, int cap)
{
edge[cnt].u = u;
edge[cnt].v = v;
edge[cnt].cap = cap;
edge[cnt].flow = ;
edge[cnt].next = head[u];
head[u] = cnt++; edge[cnt].u = v;
edge[cnt].v = u;
edge[cnt].flow = ;
edge[cnt].cap = ;
edge[cnt].next = head[v];
head[v] = cnt++;
}
bool BFS()
{
memset(vis,false,sizeof(vis));
queue<int>q;
d[source] = ;
vis[source] = true;
q.push(source);
while (!q.empty())
{
int u = q.front(); q.pop();
for (int i = head[u]; i != -; i = edge[i].next)
{
node & e = edge[i];
if (!vis[e.v] && e.cap > e.flow)
{
vis[e.v] = true;
d[e.v] = d[u] + ;
q.push(e.v);
}
}
}
return vis[target];
}
int DFS(int x,int a)
{
if (x == target || a == ) return a;
int flow = ,f;
for (int & i = cur[x]; i != -; i = edge[i].next)
{
node & e = edge[i];
if (d[x] + == d[e.v] && (f = DFS(e.v,min(a,e.cap - e.flow))) > )
{
e.flow += f;
edge[i ^ ].flow -= f;
flow += f;
a -= f;
if (a == ) break;
}
}
return flow;
}
int Maxflow(int S,int T)
{
source = S;
target = T;
int flow = ;
while (BFS())
{
for(int i=; i<=n; i++) cur[i]=head[i];
flow += DFS(source,INF);
//cout<<flow<<endl;
}
return flow;
}
};
struct point
{
int x,y;
int a,b;
}p[MAXN];
double dist(int i,int j)
{
double a=(p[i].x-p[j].x)*(p[i].x-p[j].x)*1.0;
double b=(p[i].y-p[j].y)*(p[i].y-p[j].y)*1.0;
return sqrt(a+b);
}
Dicnc ans;
int N;
double D;
int main()
{
//freopen("sample.txt","r",stdin);
int T;
scanf("%d",&T);
while (T--)
{
scanf("%d%lf",&N,&D);
int sum = ;
for (int i = ; i <= N; i++) { scanf("%d%d%d%d",&p[i].x,&p[i].y,&p[i].a,&p[i].b); sum += p[i].a;}
bool first = false;
//printf("%d\n",sum);
for (int k = ; k <= N; k++)
{
ans.init( * N + );
for (int i = ; i <= N; i++)
{
ans.addedge(,i,p[i].a);
ans.addedge(i,i + N,p[i].b);
}
for (int i = ; i <= N; i++)
for (int j = i + ; j <= N; j++)
if (dist(i,j) <= D)
{
ans.addedge(i + N,j,INF);
ans.addedge(j + N,i,INF);
}
int temp = ans.Maxflow(,k);
if (sum == temp)
{
if (!first) {printf("%d",k - );first = true;}
else printf(" %d",k - );
}
}
if (!first) printf("-1");
puts("");
}
return ;
}
UVALIVE 3972 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个企鹅离开,就会消失,问有哪些冰块可以作为集合点,就是所有企鹅都能成 ...
- 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——题解
最近的题解的故事背景割. 题目: 描述 在靠近南极的某处,一些企鹅站在许多漂浮的冰块上.由于企鹅是群居动物,所以它们想要聚集到一起,在同一个冰块上.企鹅们不想把自己的身体弄湿,所以它们在冰块之间跳跃, ...
随机推荐
- Partitioning by Palindromes UVA - 11584 简单dp
题目:题目链接 思路:预处理出l到r为回文串的子串,然后如果j到i为回文串,dp[i] = min(dp[i], dp[j] + 1) AC代码: #include <iostream> ...
- poj1182食物链
Description 动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形.A吃B, B吃C,C吃A. 现有N个动物,以1-N编号.每个动物都是A,B,C中的一种,但是我们并不知道它到 ...
- Flask错误收集 【转】
感谢大佬 ---> 原文链接 一.pydev debugger: process XXXXX is connecting 这个错误网上找了很多资料都无法解决,尝试过多种方法后,对我来说,下面这个 ...
- Linux与BSD不同
https://linux.cn/article-3186-1.html https://www.howtogeek.com/190773/htg-explains-whats-the-differe ...
- python基础之数据类型与变量patr1
1:编写for循环,利用索引遍历出每一个字符 msg='hello egon 666' 2:编写while循环,利用索引遍历出每一个字符 msg='hello egon 666' 3:msg='hel ...
- 1,Python常用库之一:Numpy
Numpy支持大量的维度数组和矩阵运算,对数组运算提供了大量的数学函数库! Numpy比Python列表更具优势,其中一个优势便是速度.在对大型数组执行操作时,Numpy的速度比Python列表的速度 ...
- 算法:枚举法---kotlin
枚举法:效率低,循环所有的情况,找到正确答案 用于解决数学问题,还是很简单的. 比如,奥数里面: 算 法 描 述 题X题=题题题题题题 其中 算法描述题每一个为一个数字,请写出正确的数字. ok,我们 ...
- ListView.getChildCount() 详解
ListView.getCount() 返回的所包含的item总个数 ListView.getChildCount() (ViewGroup.getChildCount()) 返回的是现实层面上所包含 ...
- 栈和队列&前缀,中缀,后缀
1.堆和栈的区别? (1)栈内存操作系统来分配,堆内存由程序员自己来分配. (2)栈有系统自动分配,只要栈 剩余空间大于所申请空间,系统将为程序提供内存,否则将报异常提示栈溢出. 2.栈(线性表) 仅 ...
- 剑指Offer - 九度1387 - 斐波那契数列
剑指Offer - 九度1387 - 斐波那契数列2013-11-24 03:08 题目描述: 大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项.斐波那契数列的定义如下: ...