最大流建图比较容易第一次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的更多相关文章

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

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

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

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

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

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

随机推荐

  1. 猜数字问题 python

    猜数字问题,要求如下: ① 随机生成一个整数 ② 猜一个数字并输入 ③ 判断是大是小,直到猜正确 ④ 判断时间提示:需要用time模块.random模块该题目不需要创建函数 import random ...

  2. 笔记-python-lib-contextlib

    笔记-python-lib-contextlib 1.      contextlib with 语句很好用,但不想每次都写__enter_-和__exit__方法: py标准库也为此提供了工具模块c ...

  3. 算法学习记录-图——应用之关键路径(Critical Path)

    之前我们介绍过,在一个工程中我们关心两个问题: (1)工程是否顺利进行 (2)整个工程最短时间. 之前我们优先关心的是顶点(AOV),同样我们也可以优先关心边(同理有AOE).(Activity On ...

  4. DJango跨域中间键

    Skip to main content   Search PyPISearch Help Donate Log in Register django-cors-middleware 1.3.1 pi ...

  5. USACO Section2.1 Healthy Holsteins 解题报告 【icedream61】

    holstein解题报告 --------------------------------------------------------------------------------------- ...

  6. shell脚本获取网页快照并生成缩略图

    获取网页快照并生成缩略图可分两步进行: 1.获取网页快照 2.生成缩略图 获取网页快照 这里我们用 phantomjs 来实现.关于 phantomjs 的详细用法可参考官方网站. 1.安装 我的环境 ...

  7. window.parent 、window.top及window.self 详解

    在应用有frameset或者iframe的页面时,parent是父窗口,top是最顶级父窗口(有的窗口中套了好几层frameset或者iframe),self是当前窗口. 1. window.self ...

  8. 关于MySQL查询优化 の 30条忠告

    撸自:http://www.jincon.com/archives/120/ 1.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引. 2.应尽量避 ...

  9. jQuery制作table表格布局插件带有列左右拖动效果

    压缩包:http://www.xwcms.net/js/bddm/99004.html

  10. MySQL 主主同步

    双机热备的概念简单说一下,就是要保持两个数据库的状态自动同步.对任何一个数据库的操作都自动应用到另外一个数据库,始终保持两个数据库数据一致. 这样做的好处多. 1. 可以做灾备,其中一个坏了可以切换到 ...