BZOJ 1449 JSOI2009 球队收益 费用流
题目大意:给定n支球队。第i支球队已经赢了wini场。输了losei场,接下来还有m场比赛。每一个球队终于的收益为Ci∗x2i+Di∗y2i,当中xi为终于的胜场,yi为终于的负场
求最小化收益
考虑一仅仅球队,其收益与在接下来的比赛中的胜场数关系为:
赢0场 Ci∗win2i+Di∗(di+losei)2
赢1场 Ci∗(wini+1)2+Di∗(di+losei−1)2
赢2场 Ci∗(wini+2)2+Di∗(di+losei−2)2
…
赢di场 Ci∗(wini+di)2+Di∗lose2i
差分后可得:
赢第1场 Ci∗(2∗wini+1)−Di∗[2∗(di+losei)−1]
赢第2场 Ci∗(2∗wini+3)−Di∗[2∗(di+losei)−3]
…
赢第di场 Ci∗[2∗wini+(2∗di−1)]−Di∗[2∗(di+losei)−(2∗di−1)]
easy发现差分后单调递增。故收益是关于胜场数的一个下凸函数,能够拆边做
于是我们将每支球队和每场比赛都变成一个点,建图跑费用流
源点向第i个点连di条边。流量为1。第j条边的费用为Ci∗[2∗wini+(2∗j−1)]−Di∗[2∗(di+losei)−(2∗j−1)]
每场比赛的两方向这场比赛连一条流量为1费用为0的边
每场比赛向汇点连一条流量为1费用为0的边
最小费用+∑ni=1[Ci∗win2i+Di∗(di+losei)2]就是答案
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define M 6060
#define S 0
#define T (M-1)
#define INF 0x3f3f3f3f
using namespace std;
int n,m,ans;
int win[M],lose[M],C[M],D[M],d[M];
namespace Min_Cost_Max_Flow{
struct abcd{
int to,flow,cost,next;
}table[1001001];
int head[M],tot=1;
void Add(int x,int y,int f,int c)
{
table[++tot].to=y;
table[tot].flow=f;
table[tot].cost=c;
table[tot].next=head[x];
head[x]=tot;
}
void Link(int x,int y,int f,int c)
{
Add(x,y,f,c);
Add(y,x,0,-c);
}
bool Edmonds_Karp()
{
static int q[65540],cost[M],flow[M],from[M];
static unsigned short r,h;
static bool v[M];
int i;
memset(cost,0x3f,sizeof cost);
cost[S]=0;flow[S]=INF;q[++r]=S;
while(r!=h)
{
int x=q[++h];v[x]=false;
for(i=head[x];i;i=table[i].next)
if(table[i].flow&&cost[table[i].to]>cost[x]+table[i].cost)
{
cost[table[i].to]=cost[x]+table[i].cost;
flow[table[i].to]=min(flow[x],table[i].flow);
from[table[i].to]=i;
if(!v[table[i].to])
v[table[i].to]=true,q[++r]=table[i].to;
}
}
if(cost[T]==0x3f3f3f3f) return false;
ans+=cost[T]*flow[T];
for(i=from[T];i;i=from[table[i^1].to])
table[i].flow-=flow[T],table[i^1].flow+=flow[T];
return true;
}
}
int main()
{
using namespace Min_Cost_Max_Flow;
int i,j,x,y;
cin>>n>>m;
for(i=1;i<=n;i++)
scanf("%d%d%d%d",&win[i],&lose[i],&C[i],&D[i]);
for(i=1;i<=m;i++)
{
scanf("%d%d",&x,&y);
Link(x,n+i,1,0);
Link(y,n+i,1,0);
Link(n+i,T,1,0);
d[x]++;d[y]++;
}
for(i=1;i<=n;i++)
{
ans+=C[i]*win[i]*win[i]+D[i]*(d[i]+lose[i])*(d[i]+lose[i]);
for(j=1;j<=d[i];j++)
Link(S,i,1, C[i]*(2*win[i]+j*2-1)-D[i]*(2*(d[i]+lose[i])-j*2+1) );
}
while( Edmonds_Karp() );
cout<<ans<<endl;
return 0;
}
BZOJ 1449 JSOI2009 球队收益 费用流的更多相关文章
- BZOJ 1449: [JSOI2009]球队收益( 最小费用最大流)
先考虑假如全部输了的收益. 再考虑每场比赛球队赢了所得收益的增加量,用这个来建图.. --------------------------------------------------------- ...
- bzoj 1449 [JSOI2009]球队收益(费用拆分,最小费用流)
1449: [JSOI2009]球队收益 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 547 Solved: 302[Submit][Status][ ...
- BZOJ 1449: [JSOI2009]球队收益 最小费用最大流 网络流
https://www.lydsy.com/JudgeOnline/problem.php?id=1449 给每条路加上一个权值,每条路的费用是这条路的流量*权值,求最大流的最小费用. 每次spfa记 ...
- [bzoj 1449] 球队收益(费用流)
[bzoj 1449] 球队收益(费用流) Description Input Output 一个整数表示联盟里所有球队收益之和的最小值. Sample Input 3 3 1 0 2 1 1 1 1 ...
- 【BZOJ 1449】 1449: [JSOI2009]球队收益 (最小费用流)
1449: [JSOI2009]球队收益 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 841 Solved: 483 Description Inpu ...
- 1449: [JSOI2009]球队收益
1449: [JSOI2009]球队收益 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 757 Solved: 437[Submit][Status][ ...
- bozj 1449/2895: 球队预算 -- 费用流
2895: 球队预算 Time Limit: 10 Sec Memory Limit: 256 MB Description 在一个篮球联赛里,有n支球队,球队的支出是和他们的胜负场次有关系的,具体 ...
- 【BZOJ1449】[JSOI2009]球队收益(网络流,费用流)
[BZOJ1449][JSOI2009]球队收益(网络流,费用流) 题面 BZOJ 洛谷 题解 首先对于一支队伍而言,总共进行多少场比赛显然是已知的,假设是\(n_i\)场,那么它的贡献是:\(C_i ...
- BZOJ1449[JSOI2009]球队收益&BZOJ2895球队预算——最小费用最大流
题目描述 输入 输出 一个整数表示联盟里所有球队收益之和的最小值. 样例输入 3 3 1 0 2 1 1 1 10 1 0 1 3 3 1 2 2 3 3 1 样例输出 43 提示 要求总费用最低 ...
随机推荐
- Swift - 给表格的单元格UITableViewCell添加图片,详细文本标签
表格UITableView中,每一单元格都是一个UITableViewCell.其支持简单的自定义,比如在单元格的内部,添加图片和详细文本标签. 注意UITableViewCell的style: (1 ...
- 在Delphi中使用C++对象(两种方法,但都要改造C++提供的DLL)
Delphi是市场上最好的RAD工具,但是现在C++占据着主导地位,有时针对一个问题很难找到Delphi或Pascal的解决方案.可是却可能找到了一个相关的C++类.本文描述几种在Delphi代码中使 ...
- Socket编程之聊天程序 - 模拟Fins/ModBus协议通信过程
设备控制软件编程涉及到的基本通信方式主要有TCP/IP与串口,用到的数据通信协议有Fins与ModBus. 更高级别的通信如.net中的Remoting与WCF在进行C/S架构软件开发时会采用. 本篇 ...
- 《转》 Openstack Grizzly 指定 compute node 创建 instance
声明:此文档仅仅做学习交流使用,请勿用作其它商业用途 作者:朝阳_tony 邮箱:linzhaolover@gmail.com 2013年6月4日9:37:44 星期二 转载请注明出处:http:// ...
- c++实用技巧
原地址:http://www.cnblogs.com/easymind223/articles/2576904.html 晚上的时间总是习惯性的在cnblogs逛街,今天又看到了好文章,其c++味道浓 ...
- System单元对所有与COM相关的声明就这么多,需要倒背如流
是首先是VM表,但是和COM相关的函数地址都废弃了,这几个VM函数具体放在哪里,还得在研究: { Virtual method table entries } vmtSelfPtr = -; vmtI ...
- [Word使用笔记]分类简介
什么Vistual Studio , Eclipse , Xcode , 都弱爆了,Word比他们难多了 - -! 此分类用于记录Word的一些使用
- Android 编译时出现r cannot be resolved to a variable
问题:编译出现r cannot be resolved to a variable 原因:SDK的Tools没有安装 解决:在Android SDK Manager中安装Tools部分,包括如下4项, ...
- Virtualbox mouse move in and out and file share with windows
How to use Virstalbox to share files with Linux and Windows, and to move the mouse in and out Virtua ...
- winXP JDK由1.8改为1.6
(1)直接在环境变量中删除配置的相关路径 path的值: C:\Documents and Settings\Administrator>path PATH=C:\Documents and S ...