【NOIP2016提高A组五校联考1】挖金矿

题目

Description
这里写图片描述
Input
这里写图片描述
Sample Input

4 3
4 3 3
5 1 6
2 6 1
3 2 9
Output
这里写图片描述
Sample Output
4.4286

Data Constraint
这里写图片描述
Hint
这里写图片描述

比赛时の想法

二分一下答案,但是有一些细节想错了QAQ

正解

显然是二分答案,然后我们可以得到一条不等式: anstot>=mid ,ans表示和,tot则是个数,那么把这条式子移一下,得: (a[i]mid)>0 其实在有平均数时的二分都是这样的吧QAQ~
那么我们有nh的时间找到一个最优的答案,并且判断一下是否大于零而决定二分方向即可

贴代码

var
    f:array[0..200005]of int64;
    a:array[0..100005,1..2]of longint;
    i,j:longint;
    k,l,h,n,x,y,z,r,mid,ans,tot,cy,mt,nd,cc:int64;
    p:extended;
begin
   // assign(input,'t1.in'); reset(input);
    readln(n,h);
    z:=1;
    for i:=1 to n do
    begin
        for j:=1 to h do
        begin
            read(x);
            x:=x*100000;
            f[z]:=x;
            inc(z);
            if x>r then r:=x;
        end;
    end;
    for i:=1 to n do
    begin
        a[i,1]:=a[i-1,2]+1;
        a[i,2]:=a[i-1,2]+h;
    end;
    l:=1;
    while l<r do
    begin
        mid:=(l+r) div 2;
        ans:=0;
        tot:=0;
        for i:=1 to n do
        begin
            cy:=0;
            nd:=0;
            cc:=0;
            mt:=0;
            ans:=ans+f[a[i,1]]-mid;
            tot:=tot+1;
            for j:=a[i,1]+1 to a[i,2] do
            begin
                inc(nd);
                cc:=cc+f[j]-mid;
                if cc>cy then cy:=cc;
            end;
            ans:=ans+cy;
        end;
        if ans>0 then l:=mid+1 else r:=mid;
    end;
    writeln((l/100000):0:4);
   // close(input);
end.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值