#9 //[SDOI2017]新生舞会
题解:
分数规划+费用流
常数巨大开o2加inline加register还是不行
我也不知道为什么
代码:
#include <bits/stdc++.h>
using namespace std;
const int N=5e4;
const int N1=2e3;
#define INF 1e9
#define INF2 1e4
#define eps 1e-7
#define rg register
#define IL inline
int pre[N],aa[N],s,t,n,m;
double dis[N];
bool vis[];
int l,p1[N1][N1],p2[N1][N1],head[];
struct re{
int a,b,c,flow,from;
double cost;
}a[N];
IL void arr(int x,int y,int z,int flow,double cost)
{
a[++l].a=head[x];
a[l].b=y;
a[l].c=z;
a[l].flow=flow;
a[l].from=x;
a[l].cost=cost;
head[x]=l;
}
IL bool bellmanford(double &flow,double &cost)
{
queue<int>q;
for (rg int i=;i<=t;i++) dis[i]=INF;
aa[s]=INF;
memset(vis,,sizeof(vis));
q.push(s);
while (!q.empty())
{
rg int x=q.front(); q.pop();
rg int u=head[x];
while (u)
{
rg int v=a[u].b;
if (dis[x]+a[u].cost<dis[v]&&a[u].c>a[u].flow)
{
dis[v]=dis[x]+a[u].cost;
aa[v]=min(aa[x],a[u].c-a[u].flow);
pre[v]=u;
if (vis[v])
{
vis[v]=; q.push(v);
}
}
u=a[u].a;
}
vis[x]=;
}
if (dis[t]==INF) return();
rg int x=t; flow+=aa[t]; cost+=aa[t]*dis[t];
while (pre[x])
{
rg int y=pre[x];
a[y].flow+=aa[t];
if (y%==) a[y+].flow-=aa[t];
else a[y-].flow-=aa[t];
x=a[y].from;
}
return ;
}
double flow,cost;
IL void mincost()
{
while (bellmanford(flow,cost));
}
#define mid (h+t)/2
IL bool check(double x)
{
l=;
memset(head,,sizeof(head));
for (rg int i=;i<=n;i++)
for (rg int j=;j<=n;j++)
{
arr(i,j+n,,,-(p1[i][j]-p2[i][j]*x));
arr(j+n,i,,,(p1[i][j]-p2[i][j]*x));
}
s=,t=*n+;
for (rg int i=;i<=n;i++)
{
arr(,i,,,); arr(i,,,,);
arr(i+n,t,,,); arr(t,i+n,,,);
}
flow=; cost=;
mincost();
if (cost<=) return();
else return();
}
int main()
{
std::ios::sync_with_stdio(false);
cin>>n;
for (rg int i=;i<=n;i++)
for (rg int j=;j<=n;j++)
cin>>p1[i][j];
for (rg int i=;i<=n;i++)
for (rg int j=;j<=n;j++)
cin>>p2[i][j];
double h=,t=INF2;
while (t-h>eps)
{
if (check(mid)) h=mid;
else t=mid;
}
printf("%.6f",h);
return ;
}
#9 //[SDOI2017]新生舞会的更多相关文章
- [Sdoi2017]新生舞会 [01分数规划 二分图最大权匹配]
[Sdoi2017]新生舞会 题意:沙茶01分数规划 貌似\(*10^7\)变成整数更科学 #include <iostream> #include <cstdio> #inc ...
- BZOJ_4819_[Sdoi2017]新生舞会_01分数规划+费用流
BZOJ_4819_[Sdoi2017]新生舞会_01分数规划+费用流 Description 学校组织了一次新生舞会,Cathy作为经验丰富的老学姐,负责为同学们安排舞伴.有n个男生和n个女生参加舞 ...
- 洛谷 P3705 [SDOI2017]新生舞会 解题报告
P3705 [SDOI2017]新生舞会 题目描述 学校组织了一次新生舞会,\(Cathy\)作为经验丰富的老学姐,负责为同学们安排舞伴. 有\(n\)个男生和\(n\)个女生参加舞会买一个男生和一个 ...
- 【BZOJ 4819】 4819: [Sdoi2017]新生舞会 (0-1分数规划、二分+KM)
4819: [Sdoi2017]新生舞会 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 601 Solved: 313 Description 学校 ...
- 【BZOJ4819】[Sdoi2017]新生舞会 01分数规划+费用流
[BZOJ4819][Sdoi2017]新生舞会 Description 学校组织了一次新生舞会,Cathy作为经验丰富的老学姐,负责为同学们安排舞伴.有n个男生和n个女生参加舞会 买一个男生和一个女 ...
- [BZOJ4819][SDOI2017]新生舞会(分数规划+费用流,KM)
4819: [Sdoi2017]新生舞会 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1097 Solved: 566[Submit][Statu ...
- 【算法】01分数规划 --- HNOI2009最小圈 & APIO2017商旅 & SDOI2017新生舞会
01分数规划:通常的问法是:在一张有 \(n\) 个点,\(m\) 条边的有向图中,每一条边均有其价值 \(v\) 与其代价 \(w\):求在图中的一个环使得这个环上所有的路径的权值和与代价和的比率最 ...
- 4819: [Sdoi2017]新生舞会(分数规划)
4819: [Sdoi2017]新生舞会 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1031 Solved: 530[Submit][Statu ...
- 题解:SDOI2017 新生舞会
题解:SDOI2017 新生舞会 Description 学校组织了一次新生舞会,Cathy 作为经验丰富的老学姐,负责为同学们安排舞伴. 有 \(n\) 个男生和 \(n\) 个女生参加舞会.一个男 ...
- bzoj4819 [Sdoi2017]新生舞会
Description 学校组织了一次新生舞会,Cathy作为经验丰富的老学姐,负责为同学们安排舞伴.有n个男生和n个女生参加舞会买一个男生和一个女生一起跳舞,互为舞伴.Cathy收集了这些同学之间的 ...
随机推荐
- Java编程思想 学习笔记3
三.操作符 1.优先级 当一个表达式中存在多个操作符时,操作符的优先级就决定了各部分的计算顺序.程序员常常忘记其他优先级规则,所以应该用括号明确规定计算顺序. 当编译器观察到一个String后面紧跟着 ...
- postgresql 随机函数
随机函数 --function to get random number============================================================= -- ...
- 解决从本地文件系统上传到HDFS时的权限问题
当使用 hadoop fs -put localfile /user/xxx 时提示: put: Permission denied: user=root, access=WRITE, inode=& ...
- Git查看单个文件修改历史
1 命令 git log --pretty=oneline 文件名 ➜ admin git:(feature/v1.5.0_20181202_group) git log --pretty=onel ...
- Native、Web App、Hybrid、React Native(简称RN)、Weex 间的异同点。
App常用开发模式简介 此处App为应用application,并非我们通常讲的手机App. 常用的几种APP开发模式-脑图 Native App 传统的原生App开发模式,有iOS和aOS两大系统, ...
- Java读取txt文件——(二)
Txt数据
- shiro与Web项目整合-Spring+SpringMVC+Mybatis+Shiro(八)
Jar包
- ubuntu14.04 VIM for python 一键配置
# 超强vim配置文件 [](https://travis-ci. ...
- Async 详解
一:流程控制 为了适应异步编程,减少回调的嵌套,我尝试了很多库.最终觉得还是async最靠谱. 地址:https://github.com/caolan/async Async的内容分为三部分: 流程 ...
- springboot系列十三、springboot集成swaggerUI
一.Swagger介绍 Swagger能成为最受欢迎的REST APIs文档生成工具之一,有以下几个原因: Swagger 可以生成一个具有互动性的API控制台,开发者可以用来快速学习和尝试API. ...