网络流/费用流/二分图最小权匹配


  题解:http://blog.csdn.net/huzecong/article/details/9119741

  太神了!由于一赢一输不好建图,就先假设全部都输,再将赢的收益修改!就变成普通的二分图了!!

  费用与流量的平方相关时拆边……这个稍微处理一下即可

 /**************************************************************
Problem: 1449
User: Tunix
Language: C++
Result: Accepted
Time:676 ms
Memory:3940 kb
****************************************************************/ //BZOJ 1449
#include<cmath>
#include<vector>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;++i)
#define F(i,j,n) for(int i=j;i<=n;++i)
#define D(i,j,n) for(int i=j;i>=n;--i)
#define pb push_back
#define CC(a,b) memset(a,b,sizeof(a))
using namespace std;
int getint(){
int v=,sign=; char ch=getchar();
while(!isdigit(ch)) {if(ch=='-') sign=-; ch=getchar();}
while(isdigit(ch)) {v=v*+ch-''; ch=getchar();}
return v*sign;
}
const int N=,M=,INF=~0u>>;
typedef long long LL;
const double eps=1e-;
/*******************template********************/
int n,m,w[N],l[N],c[N],d[N],du[N];
LL ans;
struct edge{int from,to,v,c;};
struct Net{
edge E[M];
int head[N],next[M],cnt;
void ins(int x,int y,int z,int c){
E[++cnt]=(edge){x,y,z,c};
next[cnt]=head[x]; head[x]=cnt;
}
void add(int x,int y,int z,int c){
ins(x,y,z,c); ins(y,x,,-c);
}
int S,T,d[N],from[N],Q[M];
bool inq[N];
bool spfa(){
int l=,r=-;
F(i,,T)d[i]=INF;
d[S]=; Q[++r]=S; inq[S]=;
while(l<=r){
int x=Q[l++]; inq[x]=;
for(int i=head[x];i;i=next[i])
if(E[i].v && d[x]+E[i].c<d[E[i].to]){
d[E[i].to]=d[x]+E[i].c;
from[E[i].to]=i;
if(!inq[E[i].to]){
Q[++r]=E[i].to;
inq[E[i].to]=;
}
}
}
return d[T]!=INF;
}
void mcf(){
int x=INF;
for(int i=from[T];i;i=from[E[i].from])
x=min(x,E[i].v);
for(int i=from[T];i;i=from[E[i].from]){
E[i].v-=x;
E[i^].v+=x;
}
ans+=x*d[T];
}
void init(){
n=getint(); m=getint(); cnt=; ans=;
S=; T=n+m+;
F(i,,n){
w[i]=getint();l[i]=getint();
c[i]=getint();d[i]=getint();
// ans+=w[i]*w[i]*c[i]+l[i]*l[i]*d[i];
}
int x,y;
F(i,,m){
x=getint(); y=getint();
du[x]++; du[y]++;
add(x,i+n,,); add(y,i+n,,);
add(i+n,T,,);
l[x]++; l[y]++;
}
F(i,,n) ans+=w[i]*w[i]*c[i]+l[i]*l[i]*d[i]; F(i,,n) F(j,,du[i])
add(S,i,,((j+w[i])*-)*c[i] - ((l[i]-j+)*-)*d[i] );
while(spfa()) mcf();
printf("%lld\n",ans);
}
}G1;
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
#endif
G1.init();
return ;
}

1449: [JSOI2009]球队收益

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 516  Solved: 283
[Submit][Status][Discuss]

Description

Input

Output

一个整数表示联盟里所有球队收益之和的最小值。

Sample Input

3 3
1 0 2 1
1 1 10 1
0 1 3 3
1 2
2 3
3 1

Sample Output

43

HINT

Source

[Submit][Status][Discuss]

【BZOJ】【1449】【JSOI2009】球队收益的更多相关文章

  1. bzoj 1449 [JSOI2009]球队收益(费用拆分,最小费用流)

    1449: [JSOI2009]球队收益 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 547  Solved: 302[Submit][Status][ ...

  2. BZOJ 1449: [JSOI2009]球队收益( 最小费用最大流)

    先考虑假如全部输了的收益. 再考虑每场比赛球队赢了所得收益的增加量,用这个来建图.. --------------------------------------------------------- ...

  3. BZOJ 1449 JSOI2009 球队收益 费用流

    题目大意:给定nn支球队.第ii支球队已经赢了winiwin_i场.输了loseilose_i场,接下来还有mm场比赛.每一个球队终于的收益为Ci∗x2i+Di∗y2iC_i*x_i^2+D_i*y_ ...

  4. BZOJ 1449: [JSOI2009]球队收益 最小费用最大流 网络流

    https://www.lydsy.com/JudgeOnline/problem.php?id=1449 给每条路加上一个权值,每条路的费用是这条路的流量*权值,求最大流的最小费用. 每次spfa记 ...

  5. 【BZOJ 1449】 1449: [JSOI2009]球队收益 (最小费用流)

    1449: [JSOI2009]球队收益 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 841  Solved: 483 Description Inpu ...

  6. 1449: [JSOI2009]球队收益

    1449: [JSOI2009]球队收益 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 757  Solved: 437[Submit][Status][ ...

  7. 【BZOJ1449】[JSOI2009]球队收益(网络流,费用流)

    [BZOJ1449][JSOI2009]球队收益(网络流,费用流) 题面 BZOJ 洛谷 题解 首先对于一支队伍而言,总共进行多少场比赛显然是已知的,假设是\(n_i\)场,那么它的贡献是:\(C_i ...

  8. Bzoj1449 [JSOI2009]球队收益

    Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 741  Solved: 423 Description Input Output 一个整数表示联盟里所有球 ...

  9. BZOJ1449[JSOI2009]球队收益&BZOJ2895球队预算——最小费用最大流

    题目描述 输入 输出 一个整数表示联盟里所有球队收益之和的最小值. 样例输入 3 3 1 0 2 1 1 1 10 1 0 1 3 3 1 2 2 3 3 1 样例输出 43 提示   要求总费用最低 ...

  10. 【bzoj1449/bzoj2895】[JSOI2009]球队收益/球队预算 费用流

    题目描述 输入 输出 一个整数表示联盟里所有球队收益之和的最小值. 样例输入 3 3 1 0 2 1 1 1 10 1 0 1 3 3 1 2 2 3 3 1 样例输出 43 题解 费用流 由于存在一 ...

随机推荐

  1. js各种宽高(3)

    有时候项目中会用到用js获取元素位置来定位元素,首先通过图片说明scrollWidth,clientWidth,offsetWidth的关系. JS获取各种宽度.高度的简单介绍: scrollHeig ...

  2. 配置Nginx服务

    一,安装之前准备1.nginx依赖: gcc openssl-devel pcre-devel zlib-devel    安装依赖:yum install gcc openssl-devel pcr ...

  3. Jquery数组操作技巧

    Jquery对数组的操作技巧. 1. $.each(array, [callback]) 遍历[常用]  解释: 不同于例遍 jQuery 对象的 $.each() 方法,此方法可用于例遍任何对象(不 ...

  4. .NET软件汉化小实例

    Author:KillerLegend Date:2014.6.18 From:http://www.cnblogs.com/killerlegend/p/3795577.html 好的,今天我们来汉 ...

  5. dump buffer cache

    1.基础内容: ALTER SESSION SET EVENTS 'immediate trace name buffers level n'; n取值意义: 1 只转储buffer header. ...

  6. python基础学习笔记第四天 list 元祖 字典

    一 LIST方法 列表操作包含以下函数:1.cmp(list1, list2):比较两个列表的元素 2.len(list):列表元素个数 3.max(list):返回列表元素最大值 4.min(lis ...

  7. 5.python的字符串

    在前面提起过字符串这个词,现在就来学习什么是字符串. 首先,字符串是python内置的数据类型,其特点是用引号引起来,并且可以是使用单引号('字符串'),双引号("字符串"),三个 ...

  8. 分享O'Reilly最新C语言指针数据

    1.推荐书名 Understanding.and.Using.C.Pointers.pdf 2. 本书目录 Table of Content Chapter 1. Introduction Chapt ...

  9. Android--从相册中选取照片并返回结果

    启动系统相册去选择图片 //从相册中选取的方法 private void selectPhoto(){ Intent intent = new Intent(Intent.ACTION_PICK); ...

  10. hdu 1381 Crazy Search

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1381 Crazy Search Description Many people like to sol ...