• wqy的ACM赛H淮南子


    把题目给的式子展开,发现是一组二次函数.
    直接对称轴求最小值即可.

    #include <algorithm>
    #include <iostream>
    #include <cstdlib>
    #include <cstring>
    #include <cstdio>
    #include <string>
    #include <vector>
    #include <queue>
    #include <cmath>
    #include <ctime>
    #include <map>
    #include <set>
    #define MEM(x,y) memset ( x , y , sizeof ( x ) )
    #define rep(i,a,b) for (int i = (a) ; i <= (b) ; ++ i)
    #define per(i,a,b) for (int i = (a) ; i >= (b) ; -- i)
    #define pii pair < int , int >
    #define one first
    #define two second
    #define rint read<int>
    #define int long long
    #define pb push_back
    #define db double
    
    using std::queue ;
    using std::set ;
    using std::pair ;
    using std::max ;
    using std::min ;
    using std::priority_queue ;
    using std::vector ;
    using std::swap ;
    using std::sort ;
    using std::unique ;
    using std::greater ;
    
    template < class T >
        inline T read () {
            T x = 0 , f = 1 ; char ch = getchar () ;
            while ( ch < '0' || ch > '9' ) {
                if ( ch == '-' ) f = - 1 ;
                ch = getchar () ;
            }
           while ( ch >= '0' && ch <= '9' ) {
                x = ( x << 3 ) + ( x << 1 ) + ( ch - 48 ) ;
                ch = getchar () ;
           }
           return f * x ;
    }
    
    const int N = 1e5 + 100 ;
    
    int n , v[N] , ans ;
    double sum ;
    
    signed main (int argc , char * argv[]) {
        n = rint () ;
        rep ( i , 1 , n ) v[i] = rint () , sum += v[i] ;
        db d = sum / (db) n ;
        int tmp = d < 0.0 ? (db)d - 0.5 : (db)d + 0.5 ;
        printf ("%lld
    " , tmp ) ;
        rep ( i , 1 , n ) ans += ( ( v[i] - tmp ) * ( v[i] - tmp ) ) ;
        printf ("%lld
    " , ans ) ;
        system ("pause") ; return 0 ;
    }
    
  • 相关阅读:
    hdu 1181 (搜索BFS,深搜DFS,并查集)
    [置顶] ZSTACK之OSAL_Nv非易失性存储解读上
    Android中利用Fragment显示为两屏
    WCF也可以做聊天程序
    Myeclipse 连接MSSqlServer
    Mysql和Oracle的卸载
    第 5堂作业
    hdu 3421 Max Sum II
    【求助】一个菜鸟java作业,帮忙看一下错在哪儿,题目是判断回文数
    netcat使用
  • 原文地址:https://www.cnblogs.com/Equinox-Flower/p/11650101.html
Copyright © 2020-2023  润新知