去年通话邀请赛的B题,当时居然过的那么少。。。明明是一道非常裸的可行流最小流麽。。仅仅要对每种人分别求一下可行最小流加起来就能够了。建图是对每一个点拆点,容量上下届都设为v[i],然后每一个点间能连边的直接连边就能够了。然后在这个图的基础上转化为可行流最小流,求一下就能够了。。。

#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
#include<cstdio>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#define LL long long
#define inf 0x3f3f3f3f
#define CLR(a, b) memset(a, b, sizeof(a))
using namespace std; const int maxn = 440;
const int INF = 0x3f3f3f3f; struct Edge
{
int from, to, cap, flow;
Edge() {}
Edge(int from, int to, int cap, int flow)
:from(from), to(to), cap(cap), flow(flow) {}
}; struct ISAP
{
int n, m, s, t;
vector<Edge> edges;
vector<int> G[maxn]; // 邻接表,G[i][j]表示结点i的第j条边在e数组中的序号
bool vis[maxn]; // BFS使用
int d[maxn]; // 从起点到i的距离
int cur[maxn]; // 当前弧指针
int p[maxn]; // 可增广路上的上一条弧
int num[maxn]; // 距离标号计数 void AddEdge(int from, int to, int cap)
{
edges.push_back(Edge(from, to, cap, 0));
edges.push_back(Edge(to, from, 0, 0));
m = edges.size();
G[from].push_back(m-2);
G[to].push_back(m-1);
} bool BFS()
{
memset(vis, 0, sizeof(vis));
queue<int> Q;
Q.push(t);
vis[t] = 1;
d[t] = 0;
while(!Q.empty())
{
int x = Q.front();
Q.pop();
for(int i = 0; i < G[x].size(); i++)
{
Edge& e = edges[G[x][i]^1];
if(!vis[e.from] && e.cap > e.flow)
{
vis[e.from] = 1;
d[e.from] = d[x] + 1;
Q.push(e.from);
}
}
}
return vis[s];
} void init(int n)
{
this->n = n;
for(int i = 0; i < n; i++) G[i].clear();
edges.clear();
} int Augment()
{
int x = t, a = INF;
while(x != s)
{
Edge& e = edges[p[x]];
a = min(a, e.cap-e.flow);
x = edges[p[x]].from;
}
x = t;
while(x != s)
{
edges[p[x]].flow += a;
edges[p[x]^1].flow -= a;
x = edges[p[x]].from;
}
return a;
} int Maxflow(int s, int t, int need)
{
this->s = s;
this->t = t;
int flow = 0;
BFS();
memset(num, 0, sizeof(num));
for(int i = 0; i < n; i++) num[d[i]]++;
int x = s;
memset(cur, 0, sizeof(cur));
while(d[s] < n)
{
if(x == t)
{
flow += Augment();
if(flow >= need) return flow;
x = s;
}
int ok = 0;
for(int i = cur[x]; i < G[x].size(); i++)
{
Edge& e = edges[G[x][i]];
if(e.cap > e.flow && d[x] == d[e.to] + 1) // Advance
{
ok = 1;
p[e.to] = G[x][i];
cur[x] = i; // 注意
x = e.to;
break;
}
}
if(!ok) // Retreat
{
int m = n-1; // 初值注意
for(int i = 0; i < G[x].size(); i++)
{
Edge& e = edges[G[x][i]];
if(e.cap > e.flow) m = min(m, d[e.to]);
}
if(--num[d[x]] == 0) break;
num[d[x] = m+1]++;
cur[x] = 0; // 注意
if(x != s) x = edges[p[x]].from;
}
}
return flow;
}
} sol; int n, m; struct Point
{
int x, y, b, e;
int v[7];
void inpt()
{
scanf("%d%d%d%d", &x, &y, &b, &e);
e += b;
for(int i = 0; i < m; i ++)
scanf("%d", &v[i]);
}
}p[maxn]; bool ok(Point a, Point b)
{
int len = (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
return b.b > a.e && len <= (b.b - a.e) * (b.b - a.e);
} int solve(int idx)
{
sol.init(n * 2 + 5);
int S = 0, T = 2 * n + 1, SS = 2 * n + 2, ST = SS + 1;
for(int i = 1; i <= n; i ++)
{
// sol.AddEdge(i, i + n, 0);
sol.AddEdge(S, i, INF);
sol.AddEdge(i + n, T, INF); sol.AddEdge(SS, i + n, p[i].v[idx]);
sol.AddEdge(i, ST, p[i].v[idx]);
}
for(int i = 1; i <= n; i ++)
for(int j = 1; j <= n; j ++)
{
if(!ok(p[i], p[j])) continue;
sol.AddEdge(i + n, j, p[i].v[idx]);
}
sol.Maxflow(SS, ST, INF);
sol.AddEdge(T, S, INF);
sol.Maxflow(SS, ST, INF);
return sol.edges[sol.edges.size() - 2].flow;
} int main()
{
int T;
scanf("%d", &T);
while(T --)
{
scanf("%d%d", &n, &m);
n --;
scanf("%d%d", &p[0].x, &p[0].y);
p[0].b = p[0].e = 0;
for(int i = 1; i <= n; i ++)
p[i].inpt();
int ans = 0;
for(int i = 0; i < m; i ++)
ans += solve(i);
printf("%d\n", ans);
}
}

hdu 4494 Teamwork (可行流的最小流)的更多相关文章

  1. hdu 4494 Teamwork 最小费用最大流

    Teamwork Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4494 ...

  2. 有源汇有上下界最小流 DInic + 各种优化 模板

    例题:loj117 : https://loj.ac/problem/117 //其实就是判断可行流后倒着求一遍最大流 #include <iostream> #include <c ...

  3. BZOJ_2502_清理雪道_有源汇上下界最小流

    BZOJ_2502_清理雪道_有源汇上下界最小流 Description        滑雪场坐落在FJ省西北部的若干座山上. 从空中鸟瞰,滑雪场可以看作一个有向无环图,每条弧代表一个斜坡(即雪道), ...

  4. 【bzoj2502】清理雪道 有上下界最小流

    题目描述 滑雪场坐落在FJ省西北部的若干座山上. 从空中鸟瞰,滑雪场可以看作一个有向无环图,每条弧代表一个斜坡(即雪道),弧的方向代表斜坡下降的方向. 你的团队负责每周定时清理雪道.你们拥有一架直升飞 ...

  5. POJ 3801/HDU 3157 Crazy Circuits | 有下界的最小流

    题目: POJ最近总是炸 所以还是用HDU吧http://acm.hdu.edu.cn/showproblem.php?pid=3157 题解: 题很长,但其实就是给个有源汇带下界网络流(+是源,-是 ...

  6. HDU 3157 Crazy Circuits(有源汇上下界最小流)

    HDU 3157 Crazy Circuits 题目链接 题意:一个电路板,上面有N个接线柱(标号1~N),还有两个电源接线柱 + -.给出一些线路,每一个线路有一个下限值求一个能够让全部部件正常工作 ...

  7. Crazy Circuits HDU - 3157(有源汇有上下界最小流)

    给出每条边的下界 求最小流 板题 提供两个板子代码 虽然这个题 第一个比较快 但在loj上https://loj.ac/problem/117 的板题  第一个1700+ms 第二个才600+ms   ...

  8. HDU 3157 Crazy Circuits (有源汇上下界最小流)

    题意:一个电路板,上面有N个接线柱(标号1~N)   还有两个电源接线柱  +  - 然后是 给出M个部件正负极的接线柱和最小电流,求一个可以让所有部件正常工作的总电流. 析:这是一个有源汇有上下界的 ...

  9. Going Home HDU - 1533(最大费用最小流)

    On a grid map there are n little men and n houses. In each unit time, every little man can move one ...

随机推荐

  1. 04-RocketMQ入门及其使用(一)

    视频开始主要介绍数据库逻辑以及分表相关的设计. 关键的数据库读写分析操作---

  2. codeforces VK Cup 2015 - Qualification Round 1 B. Photo to Remember 水题

    B. Photo to Remember Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/522/ ...

  3. 数组、Set对象的互相转换

    一.数组与Set对象之间的转换可以实现数组的去重(数组可重复,Set不可重复) 1. 把数组对象转换为Set对象 var arr = [1,2,3,4,5,6,7,6,6,7]; console.lo ...

  4. python笔记6-%u60A0和\u60a0类似unicode解码

    前言 有时候从接口的返回值里面获取到的是类似"%u4E0A%u6D77%u60A0%u60A0"这种格式的编码,不是python里面的unicode编码. python里面的uni ...

  5. 2016年终总结--一个Python程序猿的跨界之旅

    时间过得真快.感觉15年年终总结刚写完,16年就结束了.看了blog,16年就写了可怜的8篇,对我来说16年还算顺风顺水. 真正可能出乎意料的是年底我离开了呆了2年半的龙图游戏,临时放弃了用了3年半的 ...

  6. PostgreSql 合并多行记录

    需求描述: A表有如下数据 id 1 2 3 4 B表有如下数据 id name 1 aaa 1 bbb 1 ccc 2 aa 2 bb 3 c A表和B表通过id关联,需要查询结果如下: id na ...

  7. SVG 可伸缩矢量图形 简介 Path路径

    w3school:http://www.w3school.com.cn/svg/svg_intro.asp  SVG 意为可缩放矢量图形(Scalable Vector Graphics). SVG ...

  8. java怎么删除List中的指定元素

    ArrayList al = new ArrayList(); al.add("a"); al.add("b"); //al.add("b" ...

  9. hadoop中的序列化与Writable类

    本文地址:http://www.cnblogs.com/archimedes/p/hadoop-writable-class.html,转载请注明源地址. hadoop中自带的org.apache.h ...

  10. SpringSecurity实现后台管理员登录(二)

    需求:login.ftl页面中登录成功后进入index.ftl页面中 一.pom.xml中添加json转换相关的包 <dependency> <groupId>com.fast ...