【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)手中得到了一块开发土地.据了解,这块土地是一块矩形的区域,可以纵横划 ...
随机推荐
- 在String中添加移动构造函数和移动赋值运算符
13.50 没有定义析构函数 #include<iostream> #include<string> #include<memory> #include<ut ...
- 自主创建tcpdump/wireshark pcap文件
pcap文件格式是bpf保存原始数据包的格式,很多软件都在使用,比如tcpdump.wireshark等等,了解pcap格式可以加深对原始数据包的了解,自己也可以手工构造任意的数据包进行测试. p ...
- spring beans源码解读之--XmlBeanFactory
导读: XmlBeanFactory继承自DefaultListableBeanFactory,扩展了从xml文档中读取bean definition的能力.从本质上讲,XmlBeanFactory等 ...
- hdu2030java
汉字统计 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submissio ...
- OKHttp的简单使用
一方面,最近关于OKHttp的讨论甚嚣尘上,另一方面,我最近也更新了android6.0,发现在6.0中HttpClient不能使用了,于是决定抽时间也看一下OKHttp,总结了一点东西,与大家分享. ...
- Android(java)学习笔记192:SQLite数据库(表)的创建 以及 SQLite数据库的升级
一.数据库的创建 1.文件的创建 //引用,如果文件不存在是不会创建的 File file = new File("haha.txt"): //输出流写数据 ...
- 微信45028错误,微信has no masssend quota hint错误
微信45028,微信has no masssend quota hint 微信测试账号群发出现45028,has no masssend quota hint错误 >>>>&g ...
- 9张思维导图学习Javascript(转)
思维导图小tips:思维导图又叫心智图,是表达发射性思维的有效的图形思维工具 ,它简单却又极其有效,是一种革命性的思维工具.思维导图运用图文并重的技巧,把各级主题的关系用相互隶属与相关的层级图表现出来 ...
- 第八章 CTE 递归 及 分组汇总 高级部分(多维数据集)
UNION 等集合操作符: UNION 等以第一个 SELECT 的 列明 作为 整个结果集的列明,整个结果集 唯一认可的 唯一逻辑处理阶段 是 ORDER BY 这个意思是说 只有 ORDER ...
- linux du 显示目录下的各个子目录的大小
use command du display estimate file space usage size of subdirectories [oracle@ahjcyl-db backup]$ ...