洛谷 P4307 [JSOI2009]球队收益 / 球队预算(最小费用最大流)
题面
题解
最小费用最大流
先假设剩下\(m\)场比赛,双方全输。
考虑\(i\)赢一局的贡献
\(C_i*(a_i+1)^2+D_i*(b_i-1)^2-C_i*a_i^2-D_i*b_i^2\)
\(=C _i+2*a_i*C_i+D_i-2*b_i*D_i\)
建\(m\)个点限制每场比赛只有一个人赢,自\(S\)连一条\((1, 0)\)的边
然后从这\(m\)的点连向和比赛有关的两个点一条\((1, 0)\)的边
考虑关于\(t\)的边
因为\(a_i\)和\(b_i\)会变,不能直接连一条边
然后我们观察一下上面那个式子,
显然,赢得更多,贡献就增长越大
那么,拆边,我们可以对于每个点连向\(t\)很多条边,容量为\(1\),价值是赢了对应场数的贡献
贪心地想,因为赢得更多,贡献增长越大,要最小费用,我们会先走赢得少的边
这样累加答案刚好满足条件呢
Code
#include<bits/stdc++.h>
#define LL long long
#define RG register
using namespace std;
template<class T> inline void read(T &x) {
x = 0; RG char c = getchar(); bool f = 0;
while (c != '-' && (c < '0' || c > '9')) c = getchar(); if (c == '-') c = getchar(), f = 1;
while (c >= '0' && c <= '9') x = x*10+c-48, c = getchar();
x = f ? -x : x;
return ;
}
template<class T> inline void write(T x) {
if (!x) {putchar(48);return ;}
if (x < 0) x = -x, putchar('-');
int len = -1, z[20]; while (x > 0) z[++len] = x%10, x /= 10;
for (RG int i = len; i >= 0; i--) putchar(z[i]+48);return ;
}
const int N = 10000, inf = 2147483647;
struct node {
int to, nxt, w, v;
}g[200*N];
int last[N], gl = 1;
void add(int x, int y, int w, int v) {
g[++gl] = (node) {y, last[x], w, v};
last[x] = gl;
g[++gl] = (node) {x, last[y], 0, -v};
last[y] = gl;
}
queue<int> q;
int pre[N], dis[N], from[N], s, t;
bool vis[N];
bool spfa() {
memset(dis, 127, sizeof(dis));
dis[s] = 0;
q.push(s);
while (!q.empty()) {
int u = q.front(); q.pop();
for (int i = last[u]; i; i = g[i].nxt) {
int v = g[i].to;
if (g[i].w && dis[v] > dis[u] + g[i].v) {
dis[v] = dis[u] + g[i].v; pre[v] = u; from[v] = i;
if (!vis[v]) {
vis[v] = 1;
q.push(v);
}
}
}
vis[u] = 0;
}
return dis[t] != dis[0];
}
int Mcmf() {
int ans = 0;
while (spfa()) {
int di = inf;
for (int i = t; i != s; i = pre[i]) di = min(di, g[from[i]].w);
ans += di*dis[t];
for (int i = t; i != s; i = pre[i]) g[from[i]].w -= di, g[from[i]^1].w += di;
}
return ans;
}
int a[N], b[N], c[N], d[N], cnt[N];
int main() {
int n, m, sum = 0;
read(n), read(m);
s = m+n+1, t = s+1;
for (int i = 1; i <= n; i++)
read(a[i]), read(b[i]), read(c[i]), read(d[i]);
for (int i = 1; i <= m; i++) {
int x, y;
read(x), read(y);
b[x]++, b[y]++;
cnt[x]++; cnt[y]++;
add(s, i, 1, 0);
add(i, x+m, 1, 0);
add(i, y+m, 1, 0);
}
for (int i = 1; i <= n; i++)
sum += c[i]*a[i]*a[i] + d[i]*b[i]*b[i];
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= cnt[i]; j++) {
add(i+m, t, 1, c[i]+2*a[i]*c[i]+d[i]-2*b[i]*d[i]);
b[i]--; a[i]++;
}
}
printf("%d\n", sum+Mcmf());
return 0;
}
洛谷 P4307 [JSOI2009]球队收益 / 球队预算(最小费用最大流)的更多相关文章
- 洛谷 P4009 汽车加油行驶问题 【最小费用最大流】
分层图,建k层,设(i,j,0)为点(i,j)的满油状态,全图的流量都是1,因为重复走到一个点没有意义.如果当前点是加油站,那么它向它上左的点连费用为a的边,向下右连费用为a+b的边: 否则,这个点的 ...
- BZOJ1449[JSOI2009]球队收益&BZOJ2895球队预算——最小费用最大流
题目描述 输入 输出 一个整数表示联盟里所有球队收益之和的最小值. 样例输入 3 3 1 0 2 1 1 1 10 1 0 1 3 3 1 2 2 3 3 1 样例输出 43 提示 要求总费用最低 ...
- 【BZOJ1449/2895】[JSOI2009]球队收益/球队预算 最小费用最大流
[BZOJ2895]球队预算 Description 在一个篮球联赛里,有n支球队,球队的支出是和他们的胜负场次有关系的,具体来说,第i支球队的赛季总支出是Ci*x^2+Di*y^2,Di<=C ...
- 【BZOJ-1449&2895】球队收益&球队预算 最小费用最大流
1449: [JSOI2009]球队收益 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 648 Solved: 364[Submit][Status][ ...
- 洛谷P4307 球队收益
题意:有n个球队,m场比赛. 每个球队都已经有些胜负场次了. 每个球队的收益为Ci * wini2 - Di * losei2. 求最小可能总收益. 解: 先看出一个模型:用一流量代表一个胜场,每场比 ...
- 【bzoj1449/bzoj2895】[JSOI2009]球队收益/球队预算 费用流
题目描述 输入 输出 一个整数表示联盟里所有球队收益之和的最小值. 样例输入 3 3 1 0 2 1 1 1 10 1 0 1 3 3 1 2 2 3 3 1 样例输出 43 题解 费用流 由于存在一 ...
- 【BZOJ1449】[JSOI2009]球队收益(网络流,费用流)
[BZOJ1449][JSOI2009]球队收益(网络流,费用流) 题面 BZOJ 洛谷 题解 首先对于一支队伍而言,总共进行多少场比赛显然是已知的,假设是\(n_i\)场,那么它的贡献是:\(C_i ...
- 【洛谷2469/BZOJ1927】[SDOI2010]星际竞速(费用流/最小路径覆盖)
题目: 洛谷2469 分析: 把题目翻译成人话:给一个带边权的DAG,求一个路径覆盖方案使路径边权总和最小.从点\(i\)开始的路径需要额外加上\(A_i\)的权值. 回xian忆chang一xue下 ...
- BZOJ 1449: [JSOI2009]球队收益( 最小费用最大流)
先考虑假如全部输了的收益. 再考虑每场比赛球队赢了所得收益的增加量,用这个来建图.. --------------------------------------------------------- ...
随机推荐
- Ubuntu14.04 下安装Vmware-Tools
1.切换到ubuntu 图形界面 startx , 点击虚拟机菜单栏-安装VMware Tools 2. 在Ubuntu系统中找到VMwareTools-9.2.2-893683.tar.gz ,右键 ...
- pig配置
下载Apache Pig 首先,从以下网站下载最新版本的Apache Pig:https://pig.apache.org/ 步骤1 打开Apache Pig网站的主页.在News部分下,点击链接re ...
- CF869C The Intriguing Obsession(组合数学瞎搞,O(n)莫名过)
— This is not playing but duty as allies of justice, Nii-chan! — Not allies but justice itself, Onii ...
- CodeForces 588E A Simple Task(线段树)
This task is very simple. Given a string S of length n and q queries each query is on the format i j ...
- Replication--使用备份初始化订阅--请求订阅
1. 修改发布属性"许从备份文件初始化"置为TRUE 脚本修改:USE [DB01]GODECLARE @publication AS sysnameSET @publicatio ...
- css 三彩loading
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title&g ...
- Webbench的使用
Webbench是一个在linux下使用的非常简单的网站压测工具. 它使用fork()模拟多个客户端同时访问我们设定的URL,测试网站在压力下工作的性能,最多可以模拟3万个并发连接去测试网站的负载能力 ...
- MVC MVC常见错误及解决办法
MVC常见错误及解决办法 问题1: 必须添加对程序集“EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c5 ...
- CXF动态调用wsdl接口
1.application.properties文件中配置接口url 2.工具类 package com.vulnverify.core.utils; import java.io.IOExcepti ...
- BZOJ2430 chocolate
有一个显然的想法是因为最后要花分成n*m个小块,所以每条边一定是要被切开的. 所以直接排序就可以了qwq,按照代价从大到小切一定是最优的. #include<iostream> #incl ...