#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收集了这些同学之间的 ...
随机推荐
- Visual Studio Code 常用快捷键
VsCode 快捷键有五种组合方式(科普) Ctrl + Shift + ? : 这种常规组合按钮 Ctrl + V Ctrl +V : 同时依赖一个按键的组合 Shift + V c : 先组合后单 ...
- Linux - iptable 限制 IP 访问端口
iptable 设置iptables 限制特定IP 访问: -A INPUT -s 172.16.2.20 -p tcp -j ACCEPT-A INPUT -s -p tcp -j ACCEPT 设 ...
- 前段clam安装
前端模块化协同开发解决方案 —— clam 1. 打开后直接看最后一条https://blog.csdn.net/zhangwenwu2/article/details/581720422. node ...
- 爬虫之验证码IP攻防心得——小总结
小前言: 一般来说,现在很多平台注册.登录的时候会涉及到验证码,这样做的目的是为了防止恶意程序恶意访问,从而给服务器造成一定的压力,会浪费一定的资源,大家也都知道,现在这种短信平台,邮箱平台等都是收费 ...
- 2017-2018-2 20155303 『网络对抗技术』Exp3:免杀原理与实践
2017-2018-2 20155303 『网络对抗技术』Exp3:免杀原理与实践 --------CONTENTS-------- 1. 免杀原理与实践说明 实验说明 基础问题回答 2. 使用msf ...
- C++学习3--编程基础(vector、string、三种传参)
知识点学习 Vector容器 vector是C++标准程序库中的一个类,其定义于头文件中,与其他STL组件一样,ventor属于STD名称空间: ventor是C++标准程序库里最基本的容器,设计之初 ...
- centos7版本设置OS启动默认进入图形界面还是文本界面
相比7之前的版本,在centos7版本中,设置OS启动默认进入图形界面还是文本界面有了点变化 检查当前默认设置 [root@rems2 ~]# systemctl get-default graphi ...
- python各种post上传文件
1.带证书上传文件 filename = '/tmp/test.cert'hash_v = 'assumethisisahash' #这是一种流式上传的方式with open(filename, 'r ...
- sga 操作命令
用SYS用户以SYSDBA身份登录系统alter system set sga_max_size=2000m scope=spfile;alter system set sga_target=2000 ...
- 005_awk案例实战
一.工作经验总结. (1)日志案例: 10.100.194.39 10.100.194.39 1019-03-16T11:01:04+08:00 www.uuwatch.com^^3FF91DE01B ...