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.
  • 相关阅读:
    背包问题
    计蒜客lev3
    线段树BIT操作总结
    图论题收集
    Codeforces Round #607 (Div. 2) 训练总结及A-F题解
    2-sat 学习笔记
    洛谷 P3338 【ZJOI2014】力/BZOJ 3527 力 题解
    $noi.ac$ #51 array 题解
    洛谷 P3292 【SCOI2016】幸运数字/BZOJ 4568 幸运数字 题解
    洛谷 P5283 【十二省联考2019】异或粽子 题解
  • 原文地址:https://www.cnblogs.com/BLADEVIL/p/3496076.html
Copyright © 2011-2022 走看看