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 6

Sample 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(网络流-最小割)的更多相关文章

  1. 【题解】 bzoj3894: 文理分科 (网络流/最小割)

    bzoj3894,懒得复制题面,戳我戳我 Solution: 首先这是一个网络流,应该还比较好想,主要就是考虑建图了. 我们来分析下题面,因为一个人要么选文科要么选理科,相当于两条流里面割掉一条(怎么 ...

  2. 【bzoj3774】最优选择 网络流最小割

    题目描述 小N手上有一个N*M的方格图,控制某一个点要付出Aij的代价,然后某个点如果被控制了,或者他周围的所有点(上下左右)都被控制了,那么他就算是被选择了的.一个点如果被选择了,那么可以得到Bij ...

  3. 【bzoj1143】[CTSC2008]祭祀river Floyd+网络流最小割

    题目描述 在遥远的东方,有一个神秘的民族,自称Y族.他们世代居住在水面上,奉龙王为神.每逢重大庆典, Y族都会在水面上举办盛大的祭祀活动.我们可以把Y族居住地水系看成一个由岔口和河道组成的网络.每条河 ...

  4. 【bzoj1797】[Ahoi2009]Mincut 最小割 网络流最小割+Tarjan

    题目描述 给定一张图,对于每一条边询问:(1)是否存在割断该边的s-t最小割 (2)是否所有s-t最小割都割断该边 输入 第一行有4个正整数,依次为N,M,s和t.第2行到第(M+1)行每行3个正 整 ...

  5. 【bzoj1976】[BeiJing2010组队]能量魔方 Cube 网络流最小割

    题目描述 一个n*n*n的立方体,每个位置为0或1.有些位置已经确定,还有一些需要待填入.问最后可以得到的 相邻且填入的数不同的点对 的数目最大. 输入 第一行包含一个数N,表示魔方的大小. 接下来 ...

  6. 【bzoj4177】Mike的农场 网络流最小割

    题目描述 Mike有一个农场,这个农场n个牲畜围栏,现在他想在每个牲畜围栏中养一只动物,每只动物可以是牛或羊,并且每个牲畜围栏中的饲养条件都不同,其中第i个牲畜围栏中的动物长大后,每只牛可以卖a[i] ...

  7. 【bzoj3438】小M的作物 网络流最小割

    原文地址:http://www.cnblogs.com/GXZlegend/p/6801522.html 题目描述 小M在MC里开辟了两块巨大的耕地A和B(你可以认为容量是无穷),现在,小P有n中作物 ...

  8. 【bzoj3144】[Hnoi2013]切糕 网络流最小割

    题目描述 输入 第一行是三个正整数P,Q,R,表示切糕的长P. 宽Q.高R.第二行有一个非负整数D,表示光滑性要求.接下来是R个P行Q列的矩阵,第z个 矩阵的第x行第y列是v(x,y,z) (1≤x≤ ...

  9. 【bzoj3894】文理分科 网络流最小割

    原文地址:http://www.cnblogs.com/GXZlegend 题目描述 文理分科是一件很纠结的事情!(虽然看到这个题目的人肯定都没有纠结过) 小P所在的班级要进行文理分科.他的班级可以用 ...

  10. 【bzoj2132】圈地计划 网络流最小割

    题目描述 最近房地产商GDOI(Group of Dumbbells Or Idiots)从NOI(Nuts Old Idiots)手中得到了一块开发土地.据了解,这块土地是一块矩形的区域,可以纵横划 ...

随机推荐

  1. ViewPager的用法实例

    前言:最近在做一个项目,文件管理器,能够在主界面通过滑动选择:手机,内存卡,云端的不同界面,因此就用到了ViewPager. 起步阶段,ViewPager写好了,对应的Adapter也写好了,测试通过 ...

  2. N!末尾有多少个零

    题目一:210!最后结果有几个零. 请自己思索10分钟以上再看解释 凡是这种题目必有规律可言, 关键是你找到这个规律的恒心.可采用笨拙的方法思考. 1!  =  1                   ...

  3. 传送门(portal)

    Linux: #RHEL/CentOS/fedora系列为主 Basis: Commands: Services: SpamAssassin: Tomcat: Hadoop: Hive: Pig: Z ...

  4. MDA系统分析实战--图书馆管理系统

    MDA系统分析实战--图书馆管理系统 本文通过MDA系统分析方法,对图书馆管理系统进行分析,简要叙述系统分析的一般过程.首先,简要介绍什么是MDA:MDA(Model-Driven Architect ...

  5. not exists 跟not in 纪念一下

  6. 【转】Java中equals和==的区别

    [转]Java中equals和==的区别 java中的数据类型,可分为两类: 1.基本数据类型,也称原始数据类型.byte,short,char,int,long,float,double,boole ...

  7. vs2015中ctrl+shift+F进行“在文件中查找”,有时候无效?

    搜狗拼音的默认简繁切换快捷键是ctrl+shift+F,改掉以后vs就可以收到这个按键消息了

  8. Android开发必备:颜色选择

      AA 指定透明度. 00 是完全透明. FF 是完全不透明.超出取值范围的值将被恢复为默认值.    ffff00 ffff33 ffff66 ffff99 ffffcc ffffff ffcc0 ...

  9. 在mipsel-linux平台上的编译应用SQLite-3.5.9

    sqlite 第一个Alpha版本诞生于2000年5月,是实现了SQL 92标准的一个大子集的嵌入式数据库,其以在一个库中组合了数据库引擎和接口,能将所有数据存储于单个文件中.官方测试表明sqlite ...

  10. SQL几个有点偏的语句

    SQL语句是一种集合操作,就是批量操作,它的速度要比其他的语言快,所以在设计的时候很多的逻辑都会放在sql语句或者存储过程中来实现,这个是一种设计思想.但是今天我们来讨论另外一个话题.Sql页提供了丰 ...