Problem 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∥=√x12+⋯+xn2, 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

题意

给你一个n维向量w,求∥W−αB∥2的最小值,其中B=(b1,b2,...,bn) (bi∈{+1,−1}),α≥0

题解

开始误以为是平均数最小,WA了几次后开始推式子

min(∥w−αb∥2)=min(∑(wi2-2αbiwi2bi2))

由于bi∈{+1,−1},易得bi*w≥0

=min(∑(wi2-2α|wi|+α2))=min(∑(α2-2α|wi|+wi2))=min(nα2-2α∑|wi|+∑wi2)

可知当α=∑|wi|/n时函数取到min

代入化简得=-(∑|wi|)2/n+∑wi2

通分=(n∑wi2-(∑|wi|)2)/n

gc=gcd(n∑wi2-(∑|wi|)2,n)

所以p=(n∑wi2-(∑|wi|)2)/gc,q=n/gc

代码

 #include<bits/stdc++.h>
using namespace std; #define ll long long
const int maxn=1e5+;
int a[maxn];
int main()
{
int t,n;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
ll sum=,ac=;
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
sum+=abs(a[i]);
ac+=a[i]*1LL*a[i];
}
ll gc=__gcd(ac*n-sum*sum,1LL*n);
printf("%lld/%lld\n",(ac*n-sum*sum)/gc,n/gc);
}
return ;
}

HDU 5734 Acperience(数学推导)的更多相关文章

  1. HDU 5734 Acperience (推导)

    Acperience 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5734 Description Deep neural networks (DN ...

  2. HDU 5734 Acperience ( 数学公式推导、一元二次方程 )

    题目链接 题意 : 给出 n 维向量 W.要你构造一个 n 维向量 B = ( b1.b2.b3 ..... ) ( bi ∈ { +1, -1 } ) .然后求出对于一个常数 α > 0 使得 ...

  3. HDU 5734 Acperience(返虚入浑)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  4. hdu 5734 Acperience 水题

    Acperience 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5734 Description Deep neural networks (DN ...

  5. HDU 5734 Acperience

    Acperience Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  6. hdu 5734 Acperience(2016多校第二场)

    Acperience Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  7. hdu.5211.Mutiple(数学推导 && 在logn的时间内求一个数的所有因子)

    Mutiple  Accepts: 476  Submissions: 1025  Time Limit: 4000/2000 MS (Java/Others)  Memory Limit: 6553 ...

  8. HDU 5734 Acperience (公式推导) 2016杭电多校联合第二场

    题目:传送门. #include <iostream> #include <algorithm> #include <cstdio> #include <cs ...

  9. HDU 5984 题解 数学推导 期望

    Let’s talking about something of eating a pocky. Here is a Decorer Pocky, with colorful decorative s ...

随机推荐

  1. tomcat 端口修改和内存配置

    端口号修改参考:https://jingyan.baidu.com/article/adc815139b12def722bf7377.html Tomcat内存溢出(windows) java.lan ...

  2. day052 django第三天 url和视图

    一.基本格式 from django.conf.urls import url from . import views #循环urlpatterns,找到对应的函数执行,匹配上一个路径就找到对应的函数 ...

  3. Java面向对象 第2节 Scanner 类和格式化输出printf

    §Scanner 类 java.util.Scanner 是 Java5 的新特征,我们可以通过 Scanner 类来获取用户的输入. 1.创建 Scanner 对象的基本语法:Scanner s = ...

  4. nginx实现按日期进行日志分割

    1:nginx的访问日志按日期分割,也就是每天的零点把前一天的访问日志以日期的形式备份,然后重新打开一份访问日志,这里的kill -USR1 $pid 重新打开访问日志,必须得把原来的mv,如果存在的 ...

  5. 使用pageoffice进行多个文档的合并

    提前给test模板文件中 手动插入一个书签,因为pageoffice必须有一个书签后,才能在后台进行书签的创建 //多个word文件进行合并 string strCopyFolder = System ...

  6. centos7如何安装部署Zabbix

    参考http://www.cnblogs.com/momoshouhu/p/8041293.html 1.关闭selinux和firewall 1.1检测selinux是否关闭 [root@local ...

  7. CentOS7.5下安装Mycat连接MySQL8.0

    MyCat详细介绍,请参考https://www.biaodianfu.com/mycat.html 9066管理端口,请参考https://www.cnblogs.com/parryyang/p/5 ...

  8. 配置gitlab自动备份

    在gitlab机器的root用户执行 首先,假设有2台机器. gitlab 1.1.1.1 backup 2.2.2.2 做秘钥信任 gitlab root 生成 ssh-key copy密钥到bac ...

  9. 八(第二篇)、主体结构元素——nav元素、aside元素

    nav元素 nav元素是一个可以用作页面导航的链接组,其中的导航元素链接到其他页面或当前页面的其他部分. 并不是所有的链接组都要被放进nav元素,只需要将主要的.基本的链接组放进nav元素即可. na ...

  10. 基于form表单 写登陆注册

    urls urlpatterns = [ url(r'^admin/', admin.site.urls), # 登录界面url(r'^login/$', views.login,name='logi ...