zoukankan      html  css  js  c++  java
  • bzoj 3293 数学整理

    和1045一模一样,找到这道题的时候还愣了下神,最后发现样例都是

    一样的,直接粘了1045的代码,具体题解看

    http://www.cnblogs.com/BLADEVIL/p/3468729.html

    /**************************************************************
        Problem: 3293
        User: BLADEVIL
        Language: Pascal
        Result: Accepted
        Time:296 ms
        Memory:15852 kb
    ****************************************************************/
     
    //By BLADEVIL
    var
        n                   :longint;
        a, sum              :array[0..1000010] of int64;
        i                   :longint;
        ave                 :int64;
        ans, k              :int64;
    procedure swap(var a,b:int64);
    var
        c                   :int64;
    begin
        c:=a; a:=b; b:=c;
    end;
         
    procedure qs(low,high:longint);
    var
        i, j, xx            :longint;
    begin
        i:=low; j:=high; xx:=sum[(i+j) div 2];
        while i<j do
        begin
            while sum[i]<xx do inc(i);
            while sum[j]>xx do dec(j);
            if i<=j then
            begin
                swap(sum[i],sum[j]);
                inc(i); dec(j);
            end;
        end;
        if i<high then qs(i,high);
        if j>low then qs(low,j);
    end;
         
    begin
        read(n);
        for i:=1 to n do read(a[i]);
        for i:=1 to n do sum[i]:=sum[i-1]+a[i];
        ave:=sum[n] div n;
        for i:=1 to n do sum[i]:=sum[i]-i*ave;
        qs(1,n);
        k:=sum[(1+n) div 2];
        for i:=1 to n do ans:=ans+abs(sum[i]-k);
        writeln(ans);
    end.
  • 相关阅读:
    第十四周课程总结&实验报告(简单记事本的实现)
    第十三周课程总结
    第十二周课程总结
    第十一周课程总结
    第十周课程总结
    第九周课程总结&实验报告(七)
    第八周课程总结&实验报告(六)
    第七周课程总结&实验报告(五)
    第五周课程总结&实验报告(四)
    2019JAVA课程总结
  • 原文地址:https://www.cnblogs.com/BLADEVIL/p/3496076.html
Copyright © 2011-2022 走看看