题目链接

  本来以为自己可以做出来,结果……打脸了

  (貌似来wc立了好几个flag了,都没竖起来)

  不过乱蒙能蒙出一个叫“分数规划”的东西的式子还是很开心的

  观察$C=\frac{a_{1}+a_{2}+.......+a_{n}}{b_{1}+b_{2}+.....b_{n}}$

  然后可以把分母乘到左边

  然后可以把C乘进去

  然后二分C,建图求最大权匹配,判断跟答案的关系。

  

#include<cstdio>
#include<cstdlib>
#include<cctype>
#include<algorithm>
#include<cstring>
#include<queue>
#include<cmath>
#define maxn 450
#define eps 1e-7
using namespace std; inline long long read(){
long long num=,f=;
char ch=getchar();
while(!isdigit(ch)){
if(ch=='') f=-;
ch=getchar();
}
while(isdigit(ch)){
num=num*+ch-'';
ch=getchar();
}
return num*f;
} struct Edge{
int from,next,to,val;
double dis;
}edge[maxn*maxn*];
int head[maxn],num;
inline void addedge(int from,int to,int val,double dis){
edge[++num]=(Edge){from,head[from],to,val,dis};
head[from]=num;
}
inline void add(int from,int to,int val,double dis){
addedge(from,to,val,dis);
addedge(to,from,,-dis);
}
inline void clear(){ memset(head,,sizeof(head)); num=; }
inline int count(int i){ return i&?i+:i-; } double dis[maxn];
int pre[maxn];
int flow[maxn];
bool vis[maxn];
int d[maxn][maxn];
int w[maxn][maxn];
int Start,End;
int n; double spfa(){
for(int i=Start;i<=End;++i) dis[i]=-0x7fffffff; dis[Start]=;
queue<int>q; q.push(Start); memset(flow,,sizeof(flow)); flow[Start]=0x7fffffff;
while(!q.empty()){
int from=q.front(); q.pop(); vis[from]=;
for(int i=head[from];i;i=edge[i].next){
int to=edge[i].to;
if(edge[i].val<=||dis[to]>=dis[from]+edge[i].dis) continue;
dis[to]=dis[from]+edge[i].dis;
pre[to]=i; flow[to]=min(flow[from],edge[i].val);
if(vis[to]) continue;
vis[to]=; q.push(to);
}
}
if(flow[End]==) return ;
int now=End;
while(now!=Start){
//printf("D");
int i=pre[now];
edge[i].val-=flow[End];
edge[count(i)].val+=flow[End];
now=edge[i].from;
}
return dis[End];
} bool payflow(double lim){
clear();
for(int i=;i<=n;++i){
add(Start,i,,);
add(i+n,End,,);
}
for(int i=;i<=n;++i)
for(int j=;j<=n;++j) add(i,j+n,,1.0*d[i][j]-1.0*w[i][j]*lim);
double ret=;
while(){
double now=spfa();
if(fabs(now)<=eps) break;
ret+=now;
}
return ret>;
} int main(){
n=read(); End=n*+;
for(int i=;i<=n;++i)
for(int j=;j<=n;++j) d[i][j]=read();
for(int i=;i<=n;++i)
for(int j=;j<=n;++j) w[i][j]=read();
double l=,r=1e4;double ans=;
while(r-l>eps){
double mid=(l+r)/2.0;
if(payflow(mid)){
ans=mid;
l=mid;
}
else r=mid;
}
printf("%.6lf",ans);
return ;
}

最新文章

  1. Caffe Python MemoryDataLayer Segmentation Fault
  2. Liquid Exception: Included file &#39;_includes/customizer-variables.html&#39; not found in assets/bootstrap/docs/customize.html 解决方案
  3. WorkbookDesigner mvc里面返回file
  4. PS之火焰铁锈字
  5. Android自己定义控件——3D画廊和图像矩阵
  6. AIX采用LV创ASM磁盘组
  7. 《C语言 学生成绩管理系统》
  8. English Vocabulary
  9. C++三种野指针及应对/内存泄露
  10. 二叉树的递归遍历 The Falling Leaves UVa 699
  11. MySQL修改密码的三种方法
  12. [HNOI2010]BUS 公交线路
  13. FFmpeg制作+x264+faac
  14. WEB打印控件Lodop使用体会
  15. android开发(29) 自定义曲线,可拖动,无限加载
  16. 第一个 MVC 应用程序(上半部分)(《精通 ASP.NET MVC5》 的第二章)
  17. 【AtCoder】ARC062F - AtCoDeerくんとグラフ色塗り / Painting Graphs with AtCoDeer
  18. python16_day35【算法】
  19. JQuery和JS操作LocalStorage/SessionStorage的方法(转)
  20. (数据科学学习手札54)Python中retry的简单用法

热门文章

  1. Cookie 没你不行
  2. UVA 1613 K-Graph Oddity K度图着色 (构造)
  3. 关系代数演算So Easy
  4. 洛谷 2387/BZOJ 3669 魔法森林
  5. Linux基础学习-crond系统计划任务
  6. Java 编辑html模板并生成pdf
  7. Power Calculus UVA - 1374 迭代加深搜索
  8. HDU - 4027 Can you answer these queries?(线段树)
  9. filter 作用
  10. &lt;node&gt;……express的中间件……//