我们的目标是使v/c最小化,所以构造函数g(x)=v-x*c,那么

二分一个X,判断当时的v-x*c的值是多少,然后根据g(x)函数的

单调递减性来二分,判断,直到g(x)=0的时候当前的X就是答案。

然后我直接写的tle了,这是这两天tle的第3道题了。。。再改改。。。

/**************************************************************
    Problem: 3232
    User: BLADEVIL
    Language: Pascal
    Result: Time_Limit_Exceed
****************************************************************/
 
//By BLADEVIL
const
    lim                         =1e-5;
     
var
    n, m                        :longint;
    pre, other                  :array[0..100010] of longint;
    len                         :array[0..100010] of extended;
    last                        :array[0..3010] of longint;
    tot                         :longint;
    num                         :array[0..60,0..60] of longint;
    key, heng, shu              :array[0..60,0..60] of longint;
    sum                         :longint;
    print                       :extended;
    que, d                      :array[0..3010] of longint;
    source, sink                :longint;
     
function min(a,b:extended):extended;
begin
    if a>b then min:=b else min:=a;
end;
 
function judge(x:extended):extended;
begin
    if abs(x)<lim then exit(0);
    if x<0 then exit(-1) else exit(1);
end;
     
procedure connect(x,y:longint;z:extended);
begin
    inc(tot);
    pre[tot]:=last[x];
    last[x]:=tot;
    other[tot]:=y;
    len[tot]:=z;
end;
     
procedure init;
var
    i, j                        :longint;
     
begin
    read(n,m);
    for i:=1 to n do
        for j:=1 to m do num[i,j]:=(i-1)*m+j;
    for i:=1 to n do
        for j:=1 to m do
        begin
            read(key[i,j]);
            sum:=sum+key[i,j];
        end;
    for i:=1 to n+1 do
        for j:=1 to m do read(heng[i,j]);
    for i:=1 to n do
        for j:=1 to m+1 do read(shu[i,j]);
    source:=num[n,m]+2;
    sink:=source+1;
end;
 
function bfs:boolean;
var
    q, p                        :longint;
    h, t, cur                   :longint;
begin
    fillchar(d,sizeof(d),0);
    d[source]:=1;
    h:=0; t:=1; que[1]:=source;
    while h<t do
    begin
        inc(h);
        cur:=que[h];
        q:=last[cur];
        while q<>0 do
        begin
            p:=other[q];
            if (judge(len[q])>0) and (d[p]=0) then
            begin
                inc(t);
                que[t]:=p;
                d[p]:=d[cur]+1;
                if p=sink then exit(true);
            end;
            q:=pre[q];
        end;
    end;
    exit(false);
end;
 
function dinic(x:longint;flow:extended):extended;
var
    rest, tmp                   :extended;
    q, p                        :longint;
     
begin
    if x=sink then exit(flow);
    rest:=flow;
    q:=last[x];
    while q<>0 do
    begin
        p:=other[q];
        if (judge(len[q])>0) and (d[p]=d[x]+1) and (rest>0) then
        begin
            tmp:=dinic(p,min(rest,len[q]));
            rest:=rest-tmp;
            len[q]:=len[q]-tmp;
            len[q xor 1]:=len[q xor 1]+tmp;
        end;
        q:=pre[q];
    end;
    exit(flow-rest);
end;
 
procedure main;
var
    l, r, mid                   :extended;
    cur                         :longint;
    ans                         :extended;
    i, j                        :longint;
     
begin
    l:=0; r:=90;
    while r-l>lim do
    begin
        mid:=(l+r)/2;
        fillchar(last,sizeof(last),0);
        tot:=1;
        for i:=1 to n do
            for j:=1 to m do
            begin
                connect(source,num[i,j],key[i,j]);
                connect(num[i,j],source,0);
            end;
         
        for i:=1 to n do
            for j:=1 to m do
            begin
                cur:=0;
                if i=1 then inc(cur,heng[i,j]);
                if i=n then inc(cur,heng[i+1,j]);
                if j=1 then inc(cur,shu[i,j]);
                if j=m then inc(cur,shu[i,j+1]);
                if cur>0 then
                begin
                    connect(num[i,j],sink,cur*mid);
                    connect(sink,num[i,j],0);
                end;
            end;
        for i:=1 to n-1 do
            for j:=1 to m do
            begin
                connect(num[i,j],num[i+1,j],heng[i+1,j]*mid);
                connect(num[i+1,j],num[i,j],heng[i+1,j]*mid);
            end;
        for i:=1 to n do
            for j:=1 to m-1 do
            begin
                connect(num[i,j],num[i,j+1],shu[i,j+1]*mid);
                connect(num[i,j+1],num[i,j],shu[i,j+1]*mid);
            end;
        ans:=0;
        while bfs do
            ans:=ans+dinic(source,maxlongint);
        if judge(sum-ans)>0 then l:=mid else r:=mid;
    end;
    writeln(l:0:3);
end;
 
begin
    init;
    main;
end.

bzoj 3232 01分数规划+最大权封闭子图判定的更多相关文章

  1. 2018.11.06 NOIP训练 最大获利(profit)(01分数规划+最大权闭合子图)

    传送门 好题啊. ∑i<jpi,jK∗(200−K)>X\frac{\sum_{i<j}p_{i,j}}{K*(200-K)}>XK∗(200−K)∑i<j​pi,j​​ ...

  2. LibreOJ 2003. 「SDOI2017」新生舞会 基础01分数规划 最大权匹配

    #2003. 「SDOI2017」新生舞会 内存限制:256 MiB时间限制:1500 ms标准输入输出 题目类型:传统评测方式:文本比较 上传者: 匿名 提交提交记录统计讨论测试数据   题目描述 ...

  3. BZOJ.1312.[Neerc2006]Hard Life(分数规划 最大权闭合子图)

    BZOJ 最大密度子图. 二分答案\(x\),转为求是否存在方案满足:\(边数-x*点数\geq 0\). 选一条边就必须选两个点,所以可以转成最大权闭合子图.边有\(1\)的正权,点有\(x\)的负 ...

  4. bzoj 3232 圈地游戏 —— 01分数规划+最小割建图(最大权闭合子图)

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3232 心烦意乱的时候调这道题真是...越调越气,就这样过了一晚上... 今天再认真看看,找出 ...

  5. bzoj 3232: 圈地游戏 01分数规划

    题目大意: http://www.lydsy.com/JudgeOnline/problem.php?id=3232 题解: 首先我们看到这道题让我们最优化一个分式. 所以我们应该自然而然地想到01分 ...

  6. 【bzoj 3232】圈地游戏(算法效率--01分数规划+图论--最小割)

    题目:DZY家的后院有一块地,由N行M列的方格组成,格子内种的菜有一定的价值,并且每一条单位长度的格线有一定的费用.DZY喜欢在地里散步.他总是从任意一个格点出发,沿着格线行走直到回到出发点,且在行走 ...

  7. BZOJ.4753.[JSOI2016]最佳团体(01分数规划 树形背包DP)

    题目链接 \(Description\) 每个点有费用si与价值pi,要求选一些带根的连通块,总大小为k,使得 \(\frac{∑pi}{∑si}\) 最大 \(Solution\) 01分数规划,然 ...

  8. BZOJ.4819.[SDOI2017]新生舞会(01分数规划 费用流SPFA)

    BZOJ 洛谷 裸01分数规划.二分之后就是裸最大费用最大流了. 写的朴素SPFA费用流,洛谷跑的非常快啊,为什么有人还T成那样.. 当然用二分也很慢,用什么什么迭代会很快. [Update] 19. ...

  9. 【BZOJ】4753: [Jsoi2016]最佳团体 01分数规划+树上背包

    [题意]n个人,每个人有价值ai和代价bi和一个依赖对象ri<i,选择 i 时 ri 也必须选择(ri=0时不依赖),求选择k个人使得Σai/Σbi最大.n<=2500,ai,bi< ...

随机推荐

  1. IOS基础——静态方法(类方法)和实例方法

    1.实例方法/动态方法 a).标识符:- b).调用方式:(实例对象    函数) c).实例方法在堆栈上. 2.静态方法/类方法 a).标识符:+ b).调用方式:(类    函数) c).静态方法 ...

  2. JMeter2.13 连接 sql server

    1.安装驱动 http://www.microsoft.com/zh-CN/download/details.aspx?id=11774 下载最新的即可 解压后复制势穷力竭sqljdbc.jar到 “ ...

  3. (转载)前端构建工具gulp使用

    前端构建工具gulp使用 前端自动化流程工具,用来合并文件,压缩等. Gulp官网 http://gulpjs.com/ Gulp中文网 http://www.gulpjs.com.cn/ Gulp中 ...

  4. 配置NTP服务ntpd/ntp.conf(搭建Hadoop集群可参考)

    本文拟定是在一个局域网内(比如一个Hadoop集群)设定一台NTP服务器作为整个网络的标准时间参考,使用网络(集群)内的所有机器保持时间一致!以下是详细的操作步骤: 1. 修改选定的服务器的本地时间 ...

  5. python restful 框架之 eve 外网访问设置

    官网地址: http://python-eve.org/ 配合mongodb进行crud使用起来很方便,但是部署的时候遇到一个问题,按照官网和Deom说的,servername使用 '127.0.0. ...

  6. (原创)Windows8下安装配置WAMP

    Windows8下安装配置WAMP        2013/12/28 最近这段时间一直在研究linuxshell编程,虽然还是初级水平,但比之前有了不小的进度,但是shell的命令很多,很难在短时间 ...

  7. Unable to execute dex: java.nio.BufferOverflowException. Check the Eclipse log for stack trace.

    问题提示:Unable to execute dex: java.nio.BufferOverflowException. Check the Eclipse log for stack trace. ...

  8. eclipse代码编辑快捷键

    代码提示(代码助手):alt + / 如输入e后按alt+/,则会出现以e开头的相关方法,写代码时经常按按 删除一行代码: 光标移动到该行任意位置,按ctrl+d 剪切:ctrl+x 复制:ctrl ...

  9. MongoDB复制机制实例

    MongoDB的主从复制是一个主可以多从已从又可以为主进行主从复制.在这里就是实现一主一从一个仲裁服务器使用一个数据库服务器通过提供不同的端口. 一.启动一个MongoDB服务名字是applicati ...

  10. SQLite数据库与Contentprovider(2)

    ContentProvider: 在创建ContentProvider时,需要首先使用数据库.文件系统或网络实现底层存储功能, 然后在继承ContentProvider的类中实现基本数据操作的接口函数 ...