最大流建图比较容易第一次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. PHP.22-Smart模版

    Smart模版 smarty是一个基于PHP开发的PHP模板引擎.它提供了逻辑与外在内容的分离,简单的讲,目的就是要使PHP程序员同美工分离,使用的程序员改变程序的逻辑内容不会影响到美工的页面设计,美 ...

  2. 学习网络请求返回json对应的model

    原来泛型可以这样用: 网络返回基类,返回一个code,msg,body,其中body不确定,所以,我们把它写成泛型 import org.json.JSONObject; /** * 网络请求的基类 ...

  3. LDAP操作的两种方案

    最近由于项目需要研究了一下LDAP相关知识,感觉对没接触过的人来说还是有点坑的,所以记录下来给大家分享. 由于是第一次接触,就在网上搜了一些相关的文章,照着示例代码测试,却怎么也连不上LDAP服务器, ...

  4. 网页图片很多时,加载完后再加载图片(defer:延迟加载)

    图片影响页面加载速度,可以先加载完页面,再去加载图片. defer:告诉浏览器,这里面的js代码不影响网页脚本解析,可以解析完html脚本再执行这段js代码(个人理解). 网页代码:<img s ...

  5. QBASIC教程

    Qbasic 程序设计入门 BASIC(Beginner’s All-purpose Symbolic Instruction Code 的缩写,意为初学者通用符号指令代码)语言是在1964年由美国的 ...

  6. Visual Studio 提示某个dll文件(已在Microsoft Visual Studio 外对该文件进行了修改,是否重新加载它)

    如题: Visual Studio 提示某个dll文件(已在Microsoft Visual Studio 外对该文件进行了修改,是否重新加载它) 如果选择“是”,那恭喜你,第二次生成的时候,引用这个 ...

  7. Python 列表、元组、字典及集合操作详解

    一.列表 列表是Python中最基本的数据结构,是最常用的Python数据类型,列表的数据项不需要具有相同的类型 列表是一种有序的集合,可以随时添加和删除其中的元素 列表的索引从0开始 1.创建列表 ...

  8. 5.0 Genymotion安装以及基础使用

    后续考虑到python+appium多设备并发执行,需要多台手机,所以这里就直接更新一个jenymotion,后续多设备执行直接用真机+模拟器操作!Genymotion第一步:百度搜索[Genymot ...

  9. Jforum环境搭建

    前提:搭建好JDK.JRE.Tomcat.数据库 1.之前安装了Navicat Premium,所以直接用这个创建名为jforum的MySQL数据库,默认密码为空,记得设置密码,因为Jforum要用到 ...

  10. vue 搜索匹配

    computed: { broSeachData: function() { var browesData = this.browesData, searchVal = this.searchVal; ...