题解:

分数规划+费用流

常数巨大开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 ;
}

最新文章

  1. java 单例(懒汉式)
  2. Python: 解决pip安装源被墙的问题
  3. importSTV的使用
  4. sql语句like多个条件的写法实例
  5. java_ExecutorService, CompletionService - 有返回值并行工作方式
  6. qt软键盘输入
  7. C#获取当前路径,获取当前路径的上一层路径
  8. TR069协议向导——一个帮助你了解TR069协议的简明教程(一)
  9. Struts2 学习笔记16 struts标签 part2
  10. js 小数计算为啥和想象中不一样!
  11. hp MSA50 5盘RAID5重建为4盘RAID5怎么恢复数据
  12. 软件工程(GZSD2015) 第三次作业
  13. [转] KVM storage performance and cache settings on Red Hat Enterprise Linux 6.2
  14. Linux后门权限维持手法
  15. samba服务器笔记 (一)
  16. GNU Binutils简介及基本用法
  17. 【电子基础】液晶显示器原理&#183;LCD驱动基础
  18. Druid学习---配置_DruidDataSource参考配置
  19. sqoop 数据迁移
  20. [CODECHEF]EASYEX

热门文章

  1. 通过COM组件方式实现java调用C#写的DLL文件 转
  2. JDBC preparedStatement分页和统计,批处理和事务
  3. js 原生 ajax
  4. mysql 架构~mgr具体细节分析
  5. layer弹出层的iframe页面回调
  6. 2018-2019-2 网络对抗技术 20165320 Exp5 MSF基础应用
  7. V4L2文档翻译(一)【转】
  8. 003_饿了么chaosmonkey实现
  9. nginx实现tomcat的负载均衡及企业内部应用的代理
  10. android测试点整理