【UVALive - 3487】 Duopoly(网络流-最小割)
Description
The mobile network market in country XYZ used to be dominated by two large corporations, XYZ
Telecom and XYZ Mobile. The central government recently has realized that radio frequency spectrum
is a scarce resource and wants to regulate its usage. The spectrum currently in use is divided into
300,000 channels. Any wireless service provider who wishes to use certain spectrum should apply for
licenses on these channels. While some services may require use of multiple channels, a single channel
can not be shared by different services.
The central government wants to maximize its revenue from the spectrum by putting the channels
up to an auction. The only two bidders are XYZ Telecom and XYZ Mobile. They are allowed to place
bids on combinations of channels, through which their services can communicate with the customers.
Furthermore, the government stipulates that a company can only place at most one bid on a specific
channel.
The government can only accept a subset of the bids so none of them would conflict with each
other. However, officials soon find out that it is a difficult task to determine the winning bids in order
to maximize the revenue, and they are asking for your help.Input
Standard input will contain multiple test cases. The first line of the input is a single integer T (1 ≤
T ≤ 10) which is the number of test cases. T test cases follow, each preceded by a single blank line.
Each test case has two bid description sections, which are for XYZ Telecom and XYZ Mobile,
respectively. Each section starts with an integer N (1 ≤ N ≤ 3, 000), which is the number of bids that
follow. The next N lines each contain the description for one bid, the first integer P (1 ≤ P ≤ 1, 000)
gives the price of that bid, followed by the channel numbers required by this service. A service would
require at least 1 channel and at most 32 channels. Each channel number is a positive integer and will
never exceed 300,000.Output
Results should be directed to standard output. Start each case with ‘Case #:’ on a single line, where
# is the case number starting from 1. Two consecutive cases should be separated by a single blank
line. No blank line should be produced after the last test case.
For each test case, print the maximized revenue the government is able to collect by issuing licenses
on the channels.Sample Input
2
3
45 1
51 2
62 3
4
54 1
15 2
33 3
2 4 5
5
20 1
18 2
23 4
54 3 5 6
17 7
4
36 1 2 3
28 5
47 4 7
16 6Sample Output
Case 1:
169
Case 2:
139
【题意】
有两家公司都想向政府申请某些资源的使用权,并且他们都提供了一些申请列表,列表中含有申请费用和资源种类,同一家公司的申请列表之间不含有重复的资源。政府只可以完整地接受和拒绝谋一份申请列表,问政府的最大收益是多少。
【分析】
对于一组,新建一个点连源点(或汇点),流量为费用,再连向组内的全部点(流量为INF),最后跑一遍最小割即可。
代码如下:
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
#define INF 0xfffffff
#define Maxn 600010 int st,ed;
struct node
{
int x,y,f,o,next;
}t[Maxn*];int len; int first[Maxn],dis[Maxn],sum; int mymin(int x,int y) {return x<y?x:y;} void ins(int x,int y,int f)
{
t[++len].x=x;t[len].y=y;t[len].f=f;
t[len].next=first[x];first[x]=len;t[len].o=len+;
t[++len].x=y;t[len].y=x;t[len].f=;
t[len].next=first[y];first[y]=len;t[len].o=len-;
} void init()
{
len=;
memset(first,,sizeof(first));
st=;ed=st+;sum=;
int x,now=ed;
char cc;
scanf("%d",&x);getchar();
while(x--)
{
int c,y;
scanf("%d",&c);getchar();
ins(st,++now,c);sum+=c;
while(scanf("%d%c",&y,&cc))
{
ins(now,y,INF);
if(cc=='\n') break;
}
}
scanf("%d",&x);getchar();
while(x--)
{
int c,y;
scanf("%d",&c);getchar();
ins(++now,ed,c);sum+=c;
while(scanf("%d%c",&y,&cc))
{
ins(y,now,INF);
if(cc=='\n') break;
}
}
} queue<int > q;
bool bfs()
{
while(!q.empty()) q.pop();
memset(dis,-,sizeof(dis));
q.push(st);dis[st]=;
while(!q.empty())
{
int x=q.front();q.pop();
for(int i=first[x];i;i=t[i].next) if(t[i].f>)
{
int y=t[i].y;
if(dis[y]==-)
{
dis[y]=dis[x]+;
q.push(y);
}
}
}
if(dis[ed]==-) return ;
return ;
} int ffind(int x,int flow)
{
if(x==ed) return flow;
int now=;
for(int i=first[x];i;i=t[i].next) if(t[i].f>)
{
int y=t[i].y;
if(dis[y]==dis[x]+)
{
int a=ffind(y,mymin(flow-now,t[i].f));
now+=a;
t[i].f-=a;
t[t[i].o].f+=a;
}
}
if(now==) dis[x]=;
return now;
} void max_flow()
{
int ans=;
while(bfs())
{
ans+=ffind(st,INF);
}
printf("%d\n",sum-ans);
} int main()
{
int T,kase=;
scanf("%d",&T);
while(T--)
{
init();
printf("Case %d:\n",++kase);
max_flow();
if(T) printf("\n");
}
return ;
}
[LA3487]
最后一行输出空行报WA也是坑死了。
2016-05-27 13:22:21
【UVALive - 3487】 Duopoly(网络流-最小割)的更多相关文章
- 【题解】 bzoj3894: 文理分科 (网络流/最小割)
bzoj3894,懒得复制题面,戳我戳我 Solution: 首先这是一个网络流,应该还比较好想,主要就是考虑建图了. 我们来分析下题面,因为一个人要么选文科要么选理科,相当于两条流里面割掉一条(怎么 ...
- 【bzoj3774】最优选择 网络流最小割
题目描述 小N手上有一个N*M的方格图,控制某一个点要付出Aij的代价,然后某个点如果被控制了,或者他周围的所有点(上下左右)都被控制了,那么他就算是被选择了的.一个点如果被选择了,那么可以得到Bij ...
- 【bzoj1143】[CTSC2008]祭祀river Floyd+网络流最小割
题目描述 在遥远的东方,有一个神秘的民族,自称Y族.他们世代居住在水面上,奉龙王为神.每逢重大庆典, Y族都会在水面上举办盛大的祭祀活动.我们可以把Y族居住地水系看成一个由岔口和河道组成的网络.每条河 ...
- 【bzoj1797】[Ahoi2009]Mincut 最小割 网络流最小割+Tarjan
题目描述 给定一张图,对于每一条边询问:(1)是否存在割断该边的s-t最小割 (2)是否所有s-t最小割都割断该边 输入 第一行有4个正整数,依次为N,M,s和t.第2行到第(M+1)行每行3个正 整 ...
- 【bzoj1976】[BeiJing2010组队]能量魔方 Cube 网络流最小割
题目描述 一个n*n*n的立方体,每个位置为0或1.有些位置已经确定,还有一些需要待填入.问最后可以得到的 相邻且填入的数不同的点对 的数目最大. 输入 第一行包含一个数N,表示魔方的大小. 接下来 ...
- 【bzoj4177】Mike的农场 网络流最小割
题目描述 Mike有一个农场,这个农场n个牲畜围栏,现在他想在每个牲畜围栏中养一只动物,每只动物可以是牛或羊,并且每个牲畜围栏中的饲养条件都不同,其中第i个牲畜围栏中的动物长大后,每只牛可以卖a[i] ...
- 【bzoj3438】小M的作物 网络流最小割
原文地址:http://www.cnblogs.com/GXZlegend/p/6801522.html 题目描述 小M在MC里开辟了两块巨大的耕地A和B(你可以认为容量是无穷),现在,小P有n中作物 ...
- 【bzoj3144】[Hnoi2013]切糕 网络流最小割
题目描述 输入 第一行是三个正整数P,Q,R,表示切糕的长P. 宽Q.高R.第二行有一个非负整数D,表示光滑性要求.接下来是R个P行Q列的矩阵,第z个 矩阵的第x行第y列是v(x,y,z) (1≤x≤ ...
- 【bzoj3894】文理分科 网络流最小割
原文地址:http://www.cnblogs.com/GXZlegend 题目描述 文理分科是一件很纠结的事情!(虽然看到这个题目的人肯定都没有纠结过) 小P所在的班级要进行文理分科.他的班级可以用 ...
- 【bzoj2132】圈地计划 网络流最小割
题目描述 最近房地产商GDOI(Group of Dumbbells Or Idiots)从NOI(Nuts Old Idiots)手中得到了一块开发土地.据了解,这块土地是一块矩形的区域,可以纵横划 ...
随机推荐
- hadoop错误Could not obtain block blk_XXX_YYY from any node:java.io.IOException:No live nodes contain current block
错误: 10/12/08 20:10:31 INFO hdfs.DFSClient: Could not obtain block blk_XXXXXXXXXXXXXXXXXXXXXX_YYYYYYY ...
- 【转】cocos2d-x游戏开发(八)各类构造器
欢迎转载:http://blog.csdn.net/fylz1125/article/details/8521997 这篇写cocos2d-x的构造器. cocos2d-x引入自动释放机制后,创建的对 ...
- Bootstrap 样式定制-lessc编译源码
1.github上下载源码:解压:如目录bootstrap 2.新建同级目录custom-bootstrap ,在该目录下新建 如下三个文件:其实就是bootstrap下面的bootstrap.les ...
- dedeCMS修改文章更新发布时间问题
今天在dedeCMS系统中,修改或文章时发现,只要提交以后,文章发布时间便是当前时间.但有时候修改文章以后并不想把文章发布时间也更新成修改时间.我希望的是,修改文章不对时间做更改保持文章原有发布时间, ...
- javascript通过字典思想操作数据
作为一名前端程序猿,相对于后端操作数据的机会较少.然而,有些时候因为一些特殊的原因(如:需要构造成对应插件需要的数据格式,需要返回特定的数据格式等)而不得不对数据进行筛选.重构.相对于后端语言,我们没 ...
- CI框架篇之模型篇--直接操作(2)
在CI里面对数据库的操作有两种形式,一种是直接通过最原始的sql语句操作 一种则是通过CI里面的AR模型进行操作.两种操作各有千秋,应当有机的结合 现在讲解第一种操作的方式: 装载数据路操作类后就能够 ...
- Canvas保存图片保存到本地
使用Canvas绘图,将图片保存到本地方法 一.使用HTML5 a标签的download属性,将图片保存到本地,不需要链接服务器 关于download属性:HTML5 <a>标签downl ...
- CSS之关于clearfix--清除浮动
一,什么是.clearfix 你只要到Google或者Baidu随便一搜"css清除浮动",就会发现很多网站都讲到"盒子清除内部浮动时可以用到.clearfix" ...
- 虚拟机 Linux 系统增加换页空间
想在虚拟机里面安装oracle10g,发现默认的swap交换空间不满足最低要求,因为我分配的物理内存是1G,那么就按照要求需要2G的swap交换空间,默认只有1G的交换空间.添加swap交换空间的步骤 ...
- C++ 不使用virtual实现多态
不使用virtual实现多态可以用成员函数指针完成. 成员函数指针形式:返回类型(A::*指针名)(形参表) 其中A是类类型,即这个指针是指向A类的成员函数的函数指针 例如:int(A::*P)(in ...