#include <algorithm>
#include <iterator>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <cassert> /* ⊂_ヽ
  \\ Λ_Λ 来了老弟
   \('ㅅ')
    > ⌒ヽ
   /   へ\
   /  / \\
   レ ノ   ヽ_つ
  / /
  / /|
 ( (ヽ
 | |、\
 | 丿 \ ⌒)
 | |  ) /
'ノ )  Lノ */ using namespace std;
#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue typedef long long ll;
typedef unsigned long long ull;
//typedef __int128 bll;
typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii;
typedef pair<int,pii> p3; //priority_queue<int> q;//这是一个大根堆q
//priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
#define fi first
#define se second
//#define endl '\n' #define boost ios::sync_with_stdio(false);cin.tie(0)
#define rep(a, b, c) for(int a = (b); a <= (c); ++ a)
#define max3(a,b,c) max(max(a,b), c);
#define min3(a,b,c) min(min(a,b), c); const ll oo = 1ll<<;
const ll mos = 0x7FFFFFFF; //
const ll nmos = 0x80000000; //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f; //
const int mod = 1e9+;
const double esp = 1e-;
const double PI=acos(-1.0);
const double PHI=0.61803399; //黄金分割点
const double tPHI=0.38196601; template<typename T>
inline T read(T&x){
x=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
return x=f?-x:x;
}
struct FastIO {
static const int S = 4e6;
int wpos;
char wbuf[S];
FastIO() : wpos() {}
inline int xchar() {
static char buf[S];
static int len = , pos = ;
if (pos == len)
pos = , len = fread(buf, , S, stdin);
if (pos == len) exit();
return buf[pos++];
}
inline int xuint() {
int c = xchar(), x = ;
while (c <= ) c = xchar();
for (; '' <= c && c <= ''; c = xchar()) x = x * + c - '';
return x;
}
inline int xint()
{
int s = , c = xchar(), x = ;
while (c <= ) c = xchar();
if (c == '-') s = -, c = xchar();
for (; '' <= c && c <= ''; c = xchar()) x = x * + c - '';
return x * s;
}
inline void xstring(char *s)
{
int c = xchar();
while (c <= ) c = xchar();
for (; c > ; c = xchar()) * s++ = c;
*s = ;
}
inline void wchar(int x)
{
if (wpos == S) fwrite(wbuf, , S, stdout), wpos = ;
wbuf[wpos++] = x;
}
inline void wint(int x)
{
if (x < ) wchar('-'), x = -x;
char s[];
int n = ;
while (x || !n) s[n++] = '' + x % , x /= ;
while (n--) wchar(s[n]);
wchar('\n');
}
inline void wstring(const char *s)
{
while (*s) wchar(*s++);
}
~FastIO()
{
if (wpos) fwrite(wbuf, , wpos, stdout), wpos = ;
}
} io;
inline void cmax(int &x,int y){if(x<y)x=y;}
inline void cmax(ll &x,ll y){if(x<y)x=y;}
inline void cmin(int &x,int y){if(x>y)x=y;}
inline void cmin(ll &x,ll y){if(x>y)x=y;} /*-----------------------showtime----------------------*/
const int maxn = ;
int n;
int a[maxn][maxn],b[maxn][maxn]; struct E{
int v,val;
double cost;
int nxt;
}edge[maxn*maxn]; int head[maxn],gtot = ;
void addedge(int u,int v,int val,double cost){
edge[gtot].v = v;
edge[gtot].val = val;
edge[gtot].cost = cost;
edge[gtot].nxt = head[u];
head[u] = gtot++; edge[gtot].v = u;
edge[gtot].val = ;
edge[gtot].cost = -cost;
edge[gtot].nxt = head[v];
head[v] = gtot++;
} double dis[maxn];
int vis[maxn],pre[maxn],path[maxn];
bool spfa(int s,int t){
for(int i=s; i <=t; i++) dis[i] = 1000000000.0;
memset(pre, -, sizeof(pre));
memset(vis, , sizeof(vis));
queue<int>que;
que.push(s); vis[s] = ;
dis[s] = 0.0;
while(!que.empty()){
int u = que.front(); que.pop();
vis[u] = ;
for(int i=head[u]; ~i; i = edge[i].nxt){
int v = edge[i].v, val = edge[i].val;
double cost = edge[i].cost;
if(val > && dis[v] > dis[u] + cost){
dis[v] = dis[u] + cost;
pre[v] = u; path[v] = i;
if(vis[v] == ){
que.push(v);
vis[v] = ;
}
}
}
}
return pre[t] != -;
}
double mcmf(int s,int t){
int flow = ;
double cost = ;
while(spfa(s, t)){
int f = inf;
for(int i=t; i!=s; i=pre[i]){
f = min(f, edge[path[i]].val);
}
flow += f;
cost = cost + 1.0*f*dis[t];
for(int i=t; i!=s; i=pre[i]){
edge[path[i]].val -=f;
edge[path[i]^].val += f;
}
}
return cost;
}
bool check(double c){
memset(head, -, sizeof(head));
gtot = ;
int s = , t = n+n+;
for(int i=; i<=n; i++) {
addedge(s, i, , );
for(int j=; j<=n; j++){
addedge(i, j+n, , 1.0*c * b[i][j] - 1.0*a[i][j]);
}
addedge(i+n, t, , );
}
return mcmf(s, t) < 0.0;
}
int main(){
n = io.xint();
rep(i, , n) rep(j,,n) a[i][j] = io.xint() ;
rep(i, , n) rep(j,,n) b[i][j] = io.xint();
double le = ,ri = ;
while(abs(ri - le) > esp){ double mid = (le + ri)*1.0/2.0;
// debug(mid);
if(check(mid)) le = mid;
else ri = mid;
}
printf("%.6f\n", le); return ;
}

P3705 [SDOI2017]新生舞会 分数规划 费用流的更多相关文章

  1. 【bzoj4819】[Sdoi2017]新生舞会 分数规划+费用流

    题目描述 学校组织了一次新生舞会,Cathy作为经验丰富的老学姐,负责为同学们安排舞伴.有n个男生和n个女生参加舞会买一个男生和一个女生一起跳舞,互为舞伴.Cathy收集了这些同学之间的关系,比如两个 ...

  2. [BZOJ4819][SDOI2017]新生舞会(分数规划+费用流,KM)

    4819: [Sdoi2017]新生舞会 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1097  Solved: 566[Submit][Statu ...

  3. bzoj4819 [Sdoi2017]新生舞会 分数规划+最大费用最大流

    题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=4819 题解 首先上面说, \[ C = \frac{\sum\limits_{i=1}^n a ...

  4. 4819: [Sdoi2017]新生舞会 分数规划

    题目 https://www.lydsy.com/JudgeOnline/problem.php?id=4819 思路 分数规划的模板题?(好菜呀) 假如n=3吧(懒得写很长的式子) \(c=\fra ...

  5. BZOJ_4819_[Sdoi2017]新生舞会_01分数规划+费用流

    BZOJ_4819_[Sdoi2017]新生舞会_01分数规划+费用流 Description 学校组织了一次新生舞会,Cathy作为经验丰富的老学姐,负责为同学们安排舞伴.有n个男生和n个女生参加舞 ...

  6. 洛谷 P3705 [SDOI2017]新生舞会 解题报告

    P3705 [SDOI2017]新生舞会 题目描述 学校组织了一次新生舞会,\(Cathy\)作为经验丰富的老学姐,负责为同学们安排舞伴. 有\(n\)个男生和\(n\)个女生参加舞会买一个男生和一个 ...

  7. 【BZOJ4819】[Sdoi2017]新生舞会 01分数规划+费用流

    [BZOJ4819][Sdoi2017]新生舞会 Description 学校组织了一次新生舞会,Cathy作为经验丰富的老学姐,负责为同学们安排舞伴.有n个男生和n个女生参加舞会 买一个男生和一个女 ...

  8. P3705 [SDOI2017]新生舞会 01分数规划+费用流

    $ \color{#0066ff}{ 题目描述 }$ 学校组织了一次新生舞会,Cathy作为经验丰富的老学姐,负责为同学们安排舞伴. 有\(n\)个男生和\(n\)个女生参加舞会买一个男生和一个女生一 ...

  9. BZOJ 4819 Luogu P3705 [SDOI2017]新生舞会 (最大费用最大流、二分、分数规划)

    现在怎么做的题都这么水了.. 题目链接: (bzoj) https://www.lydsy.com/JudgeOnline/problem.php?id=4819 (luogu) https://ww ...

随机推荐

  1. python编码问题——解决python3 UnicodeEncodeError: 'gbk' codec can't encode character '\xXX' in position XX

    python实现爬虫遇到编码问题: error:UnicodeEncodeError: 'gbk' codec can't encode character '\xXX' in position XX ...

  2. codeforces 340 A. The Wall

    水水的一道题,只需要找xy的最小公倍数,然后找a b区间有多少个可以被xy的最小公倍数整除的数,就是答案. //============================================ ...

  3. python多线程详解

    目录 python多线程详解 一.线程介绍 什么是线程 为什么要使用多线程 二.线程实现 threading模块 自定义线程 守护线程 主线程等待子线程结束 多线程共享全局变量 互斥锁 递归锁 信号量 ...

  4. 全文检索方案Elasticsearch【Python-Django 服务端开发】

    更详细请看 https://www.elastic.co/cn/ 1. 全文检索和搜索引擎原理 商品搜索需求 当用户在搜索框输入商品关键字后,我们要为用户提供相关的商品搜索结果. 商品搜索实现 可以选 ...

  5. gradle脚本源码查看环境搭建

    背景 我刚入门学习gradle时,网上资料都是说通过gradle的api查看并学习脚本编写,但是api一般只有接口说明,并不能深入了解各个api的实现逻辑,有时就会对一些脚本的写法感到疑惑.通过搭建源 ...

  6. c#链接数据库,查找数据信息

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...

  7. [Spring cloud 一步步实现广告系统] 14. 全量索引代码实现

    上一节我们实现了索引基本操作的类以及索引缓存工具类,本小节我们开始实现加载全量索引数据,在加载全量索引数据之前,我们需要先将数据库中的表数据导出到一份文件中.Let's code. 1.首先定义一个常 ...

  8. 4、一个打了鸡血的for循环(增强型for循环)

    对于循环,我们大家应该都不陌生,例如do-while循环,while循环,for循环,今天给大家介绍一个有趣的东西——打了鸡血的for循环(增强型for循环). 首先看代码,了解一下for循环的结构: ...

  9. 算法与数据结构基础 - 滑动窗口(Sliding Window)

    滑动窗口基础 滑动窗口常用来解决求字符串子串问题,借助map和计数器,其能在O(n)时间复杂度求子串问题.滑动窗口和双指针(Two pointers)有些类似,可以理解为往同一个方向走的双指针.常用滑 ...

  10. IntelliJ IDEA + Maven + Jetty + Jersey搭建RESTful服务

    这次参考的是这个博客,完全按照这个我这里会出一些问题,一会再说就是了. https://www.cnblogs.com/puyangsky/p/5368132.html 一.首先新建一个项目,选择Ja ...