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. 深入理解iframe

    本文并不是一篇iframe API文档讲解,因此想了解iframe API的同学请移步 MDN, 我将在现在浏览器的角度与大家取探讨iframe, 因此,本文中虽然会提及一些iframe在旧浏览器中的 ...

  2. Android(java)学习笔记179:BroadcastReceiver之 有序广播和无序广播(BroadcastReceiver优先级)

    之前我们在Android(java)学习笔记178中自定义的广播是无序广播,下面我们要了解一下有序广播:   1.   我们首先了解一下有序广播和无序广播区别和联系? (1) 有序广播> 接受者 ...

  3. python matplotlib.plot画图显示中文乱码的问题

    在matplotlib.plot生成的统计图表中,中文总是无法正常显示.在网上也找了些资料,说是在程序中指定字体文件,不过那样的话需要对plot进行很多设置,而且都是说的设置坐标轴标题为中文,有时候图 ...

  4. html不同文档类型支持的元素标签

  5. mysql开启函数功能

    输入 show variables like '%func%'; 命令 会看到 log_bin_trust_function_creators 的状态,如果是OFF表示自定义函数功能是关闭的 输入命令 ...

  6. Python初学记录

    发音: 拍怂 语系:类C 特点: 1语句控制不用{}和(),而是强制用户空格或tab缩进.空格和tab数量不一定. 2解释性语言,不需要事先声明变量,即写即用. 3.list 列表可存放多种类型数据. ...

  7. adb shell dumpsys package 查看versionCode

    adb shell dumpsys package +包名 输出可以查看包名 aapt dump xmltree xxx.apk AndroidManifest.xml 查看AndroidManife ...

  8. SQL几个有点偏的语句

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

  9. struts通过Ajax返回数据时,例如对象类型,没有执行Ajax的回调函数

    <result type="json"  name="success">                 <param name=" ...

  10. oracle数据库误删恢复方法

    一.如果只是误删部分数据或者某条数据可以通过 1.select * from 误删除的表明 as of timestamp to_Date('恢复年月日  时分秒', '恢复时间格式')       ...