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——题解
最近的题解的故事背景割. 题目: 描述 在靠近南极的某处,一些企鹅站在许多漂浮的冰块上.由于企鹅是群居动物,所以它们想要聚集到一起,在同一个冰块上.企鹅们不想把自己的身体弄湿,所以它们在冰块之间跳跃, ...
随机推荐
- python使用网易邮箱发邮件
# -*- coding: UTF-8 -*- import smtplib from email.mime.text import MIMEText import email.mime.multip ...
- 笔记-python-多线程-深入-1
笔记-python-多线程-深入-1 1. 线程池 1.1. 线程池:控制同时存在的线程数量 threading没有线程池,只能自己控制线程数量. 基本有两种方式: 每间隔一段时间创建 ...
- Java集合——LinkedHashMap源码详解
个KV.LinkedHashMap不仅像HashMap那样对其进行基于哈希表和单链表的Entry数组+ next链表的存储方式,而且还结合了LinkedList的优点,为每个Entry节点增加了前驱和 ...
- ImageButton的坑 ImageButton 有问题
最近在用ImageButton,发现,我如果new ImageButton,并且 设置Warp_content,但是它并不会正真的warp,它会有一个边框. 不知道怎么回事. 后来,在代码里面使用Im ...
- 安装完最小化 RHEL/CentOS 7 后需要做的 30 件事情(二)
本文导航 -7. 安装 PHP0 -8. 安装 MariaDB 数据库 -9. 安装和配置 SSH 服务器 -10. 安装 GCC (GNU 编译器集) -11. 安装 Java 7. 安装 PHP ...
- iOS 中 AFNetworking HTTPS 的使用
由于我们公司由HTTP转HTTPS,出现了一系列问题特此记录下. 一.HTTPS 二.App Transport Security 三.iOS 中用HTTPS 注意的问题 四.使用 AFNetwork ...
- 如何写一套下拉刷新的控件?《MJRefresh原理浅析》(附Demo下载地址)
相信大家有很多人在做项目的时候都在使用MJRefresh 控件来实现下拉刷新的功能: MJRefresh经过不断的重构与更新迭代,现在不管是功能上还是代码结构上都是相当不错的,都是很值我们去学习的. ...
- C# 委托、Lambda表达式和事件——学习总结
1.概括 1.1.委托是寻址方法的.NET版本,类似C++中的指针.委托可以理解成指向函数的指针,它是类型安全的,定义了具体的参数和返回值. ——定义一个委托,实际上是定义一个类.委托是对方法的引用, ...
- 【Kth Smallest Element in a BST 】cpp
题目: Given a binary search tree, write a function kthSmallest to find the kth smallest element in it. ...
- 【Substring with Concatenation of All Words】cpp
题目: You are given a string, s, and a list of words, words, that are all of the same length. Find all ...