UVaLive 3487 Duopoly (最小割)
题意:有两个公司A和B在申请一些资源,现在给出两个公司所申请的内容,内容包括价钱和申请的资源 ,现在你做为官方,你只能拒绝一个申请或者接受一个申请,同一个资源不能两个公司都拥有,且申请的资源不能只给部分,问:作为官方,你能得到的最大利益是多少
析:就是一个最小割,因为AB两个公司,资源不能共用,只能给一个,也就是官方要舍弃一些利益让他们不共用资源,要这个舍弃的最小。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#include <list>
#include <assert.h>
#include <bitset>
#include <numeric>
#define debug() puts("++++")
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fi first
#define se second
#define pb push_back
#define sqr(x) ((x)*(x))
#define ms(a,b) memset(a, b, sizeof a)
#define sz size()
#define pu push_up
#define pd push_down
#define cl clear()
#define all 1,n,1
#define FOR(i,x,n) for(int i = (x); i < (n); ++i)
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e17;
const double inf = 1e20;
const double PI = acos(-1.0);
const double eps = 1e-3;
const int maxn = 6000 + 10;
const int maxm = 3e5 + 10;
const int mod = 1000000007;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, -1, 0, 1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c) {
return r >= 0 && r < n && c >= 0 && c < m;
} struct Edge{
int from, to, cap, flow;
}; struct Dinic{
int n, m, s, t;
vector<Edge> edges;
vector<int> G[maxn];
int d[maxn];
bool vis[maxn];
int cur[maxn]; void init(int n){
this-> n = n;
FOR(i, 0, n) G[i].cl;
edges.cl;
} void addEdge(int from, int to, int cap){
edges.pb((Edge){from, to, cap, 0});
edges.pb((Edge){to, from, 0, 0});
m = edges.sz;
G[from].pb(m - 2);
G[to].pb(m - 1);
} bool bfs(){
ms(vis, 0); vis[s] = 1;
d[s] = 0;
queue<int> q; q.push(s); while(!q.empty()){
int u = q.front(); q.pop();
for(int i = 0; i < G[u].sz; ++i){
Edge &e = edges[G[u][i]];
if(!vis[e.to] && e.cap > e.flow){
d[e.to] = d[u] + 1;
vis[e.to] = 1;
q.push(e.to);
}
}
}
return vis[t];
} int dfs(int u, int a){
if(u == t || a == 0) return a;
int flow = 0, f;
for(int &i = cur[u]; i < G[u].sz; ++i){
Edge &e = edges[G[u][i]];
if(d[e.to] == d[u] + 1 && (f = dfs(e.to, min(a, e.cap - e.flow))) > 0){
e.flow += f;
edges[G[u][i]^1].flow -= f;
flow += f;
a -= f;
if(a == 0) break;
}
}
return flow;
} int maxflow(int s, int t){
this-> s = s;
this-> t = t;
int flow = 0;
while(bfs()){ ms(cur, 0); flow += dfs(s, INF); }
return flow;
}
}; Dinic dinic; bool vis[maxn>>1][maxn>>1];
int a[maxm], b[maxm]; int main(){
ios::sync_with_stdio(false);
int T; cin >> T;
for(int kase = 1; kase <= T; ++kase){
cin >> n; cin.get();
int s = 0, t = n + 3000 + 1;
int mmax = -INF, ans = 0;
dinic.init(t + 2);
string line;
ms(vis, 0); ms(a, 0); ms(b, 0);
for(int i = 1; i <= n; ++i){
getline(cin, line);
stringstream ss(line);
int x; ss >> x;
dinic.addEdge(s, i, x);
ans += x;
while(ss >> x){
mmax = max(mmax, x);
a[x] = i;
}
}
cin >> m; cin.get();
for(int i = 1; i <= m; ++i){
getline(cin, line);
stringstream ss(line);
int x; ss >> x;
dinic.addEdge(i + n, t, x);
ans += x;
while(ss >> x){
mmax = max(mmax, x);
b[x] = i;
}
}
for(int i = 1; i <= mmax; ++i){
if(!a[i] || !b[i] || vis[a[i]][b[i]]) continue;
vis[a[i]][b[i]] = 1;
dinic.addEdge(a[i], b[i] + n, INF);
}
if(kase > 1) cout << endl;
cout << "Case " << kase << ":\n";
cout << ans - dinic.maxflow(s, t) << endl;
}
return 0;
}
UVaLive 3487 Duopoly (最小割)的更多相关文章
- 【UVALive - 3487】 Duopoly(网络流-最小割)
Description The mobile network market in country XYZ used to be dominated by two large corporations, ...
- 【LA 3487】Duopoly(图论--网络流最小割 经典题)
题意:C公司有一些资源,每种只有1个,有A.B两个公司分别对其中一些资源进行分组竞标,每组竞标对一些资源出一个总价.问C公司的最大收益. 解法:最小割.将A公司的竞标与源点相连,B公司的与汇点相连,边 ...
- UVALive 5099 Nubulsa Expo 全局最小割问题
B - Nubulsa Expo Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit S ...
- UVa1212 Duopoly(最小割)
题目大概说有两家通讯公司,它们分别有几个投标,投标各有价值且各个投标都包含几个频道,相同公司的各个投标包含频道都是互不相同的,而频道不能被同时选用.问怎么选择采取哪家公司哪些投标使得价值最大. 如此建 ...
- UVALive 5905 Pool Construction 最小割,s-t割性质 难度:3
https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...
- UVALive 3661 Animal Run(最短路解最小割)
题意:动物要逃跑,工作人员要截断从START(左上角)到END(右下角)的道路,每条边权表示拦截该条道路需要多少工作人员.问最少需要多少人才能完成拦截. 通俗地讲,就是把图一分为二所造成消耗的最小值. ...
- UVALive 5099 Nubulsa Expo 全球最小割 非网络流量 n^3
主题链接:点击打开链接 意甲冠军: 给定n个点m条无向边 源点S 以下m行给出无向边以及边的容量. 问: 找一个汇点,使得图的最大流最小. 输出最小的流量. 思路: 最大流=最小割. 所以题意就是找全 ...
- UVALive-3487 Duopoly(最小割)
题目大意:有两家公司都想向政府申请某些资源的使用权,并且他们都提供了一些申请列表,列表中含有申请费用和资源种类,同一家公司的申请列表之间不含有重复的资源.政府只可以完整地接受和拒绝谋一份申请列表,问政 ...
- UVALive 7264 Kejin Game 网络流+最小割
Kejin Game 题意:一个人有一颗技能树, 现在它想修练到某个技能 (假设为x), 现在修一个技能有3种方式: 1, 将该技能的前置技能都学完了,才能学该技能. 2, 取消一个技能 与 另一个技 ...
随机推荐
- js实现UTC时间转为北京时间,时间戳转为时间
用了阿里云的接口,发现其穿的日期是UTC格式的.需要转换. var utc_datetime = "2017-03-31T08:02:06Z"; function utc2beij ...
- 2018 Jar_Feb_Newwords
检测钩子程序 开发一个检测钩子程序的工具 - 豆丁网http://www.docin.com/p-1363993661.html pdf掺杂病毒的方法 Java的:xml文件中跳过的二进制数据在解析 ...
- 【343】MathJax、LaTex、Mathml 数学公式
参考:cnblog中添加数学公式支持 分类参考: 1. 基本功能 MathJax 我的LaTeX入门 MathJax basic tutorial and quick reference 分段函数:矩 ...
- win10为什么不能把文件直接拖拽
- delphi修改QQ快捷方式的目标地址达到在启动QQ的同时也能运行自己想要启动的EXE可执行文件
delphi修改QQ快捷方式的目标地址达到在启动QQ的同时也能运行自己想要启动的EXE可执行文件. 直接上代码,自已体会 !! Unit1.pas代码如下: unit Unit1; interface ...
- intellij idea 添加模板语句
1.说明 在intellij idea 中有很多模板语句可有使用,比如:输入sout,就可以直接生成 System.out.println();代码, 输入psvm,就可以直接生成main方法,类似这 ...
- Realm For Android详细教程
目录 1.Realm简介 2.环境配置 3.在Application中初始化Realm 4.创建实体 5.增删改查 6.异步操作 7.Demo地址(https://github.com/RaphetS ...
- vue 实例生命周期
compile template into render function 编译模板渲染方法 compile el’s ouoterHtml as template 将el的outerHTML当做模板 ...
- poj3666(DP+离散化)
题目链接:http://poj.org/problem?id=3666 思路: 看了讨论区说本题的数据比较弱,只需要考虑不减序列即可,比较懒,所以我也只写了这一部分的代码,思路都一样,能AC就行了. ...
- 360随身wifi隐藏ssid方法
360随身wifi隐藏ssid方法 以win7为例,介绍如何隐藏360随身wifi ssid方法 一. 禁止360随身wifi官方驱动自启动方法: 1. 找到360wifi自启动文件: 进入以下 ...