zoukankan      html  css  js  c++  java
  • HDU 5734 Acperience (推导)

    Acperience

    题目链接:

    http://acm.hdu.edu.cn/showproblem.php?pid=5734

    Description

    Deep neural networks (DNN) have shown significant improvements in several application domains including computer vision and speech recognition. In computer vision, a particular type of DNN, known as Convolutional Neural Networks (CNN), have demonstrated state-of-the-art results in object recognition and detection. Convolutional neural networks show reliable results on object recognition and detection that are useful in real world applications. Concurrent to the recent progress in recognition, interesting advancements have been happening in virtual reality (VR by Oculus), augmented reality (AR by HoloLens), and smart wearable devices. Putting these two pieces together, we argue that it is the right time to equip smart portable devices with the power of state-of-the-art recognition systems. However, CNN-based recognition systems need large amounts of memory and computational power. While they perform well on expensive, GPU-based machines, they are often unsuitable for smaller devices like cell phones and embedded electronics. In order to simplify the networks, Professor Zhang tries to introduce simple, efficient, and accurate approximations to CNNs by binarizing the weights. Professor Zhang needs your help. More specifically, you are given a weighted vector W=(w1,w2,...,wn). Professor Zhang would like to find a binary vector B=(b1,b2,...,bn) (bi∈{+1,−1}) and a scaling factor α≥0 in such a manner that ∥W−αB∥2 is minimum. Note that ∥⋅∥ denotes the Euclidean norm (i.e. ∥X∥=x21+⋯+x2n−−−−−−−−−−−√, where X=(x1,x2,...,xn)).

    Input

    There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case: The first line contains an integers n (1≤n≤100000) -- the length of the vector. The next line contains n integers: w1,w2,...,wn (−10000≤wi≤10000).

    Output

    For each test case, output the minimum value of ∥W−αB∥2 as an irreducible fraction "p/q" where p, q are integers, q>0.

    Sample Input

    3 4 1 2 3 4 4 2 2 2 2 5 5 6 2 3 4

    Sample Output

    5/1 0/1 10/1

    Source

    2016 Multi-University Training Contest 2
    ##题意: 求题中式子的最小值,其中Bi只能是1或-1.
    ##题解: 比赛时找规律推出了 α = Σ|Xi| / n; 但是在写的过程中姿势不好导致爆longlong, 查了一下午没看出原因... 更合理的办法是通过展开原式来推导,详见官方题解: 以后遇到关于期望、最大最小值等式子时,尽可能多推导几步再看. 不要上来就找规律导致问题复杂. ![](http://images2015.cnblogs.com/blog/764119/201608/764119-20160815174028609-1448972789.png)
    ##代码: ``` cpp #include #include #include #include #include #include #include #include #include #include #include #define LL long long #define double long long #define eps 1e-8 #define maxn 101000 #define mod 1000000007 #define inf 0x3f3f3f3f #define mid(a,b) ((a+b)>>1) #define IN freopen("in.txt","r",stdin); using namespace std;

    int n;
    LL num[maxn];

    int main(void)
    {
    //IN;

    int t; cin >> t;
    while(t--)
    {
        cin >> n;
        LL sum = 0, ans = 0;
        for(int i=1; i<=n; i++) {
            scanf("%lld", &num[i]);
            sum += abs(num[i]);
            ans += num[i] * num[i];
        }
    
        ans = n * ans - sum * sum;
    
        LL tmp = __gcd(ans, (LL)n);
    
        printf("%lld/%lld
    ", ans/tmp, n/tmp);
    }
    
    return 0;
    

    }

  • 相关阅读:
    红黑树以及与AVL树的区别
    yum安装mysql
    sql注入攻击
    http keep-alive
    csrf和xss
    点击事件跳转QQ 添加好友
    引入百度地图及出现的问题
    node 出现npm ERR! code ERR_TLS_CERT_ALTNAME_INVALID npm ERR! errno ERR_TLS_CERT_ALTNAME_INVALID npm ERR! request to https://registry.cnpmjs.org/vue-cli failed, reason:
    正则表达式校验-大于0的所有数,小数点后保留两位小数和正整数
    vue项目引入富文本编辑器(回显)
  • 原文地址:https://www.cnblogs.com/Sunshine-tcf/p/5773804.html
Copyright © 2011-2022 走看看