HDU 5734 Acperience(返虚入浑)

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

 

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., where X=(x1,x2,...,xn)).

深度神经网络(DNN)对诸如计算机视觉与语音识别等领域具有显著的改善作用。DNN在计算机视觉中的特例为卷积神经网络(CNN),这是对象识别与检测的高端成果。

卷积神经网络为对象识别与检测提供可靠结果,在三次元领域十分有用。在识别进步的同时,虚拟现实(VR by Oculus),增强现实(AR by HoloLens),与智能穿戴设备也出现了有趣的进展。合而观之,是时候为智能穿戴搭载尖端识别系统了。然而基于CNN的识别系统需要大量的内存与高超的计算性能。虽然他们在基于GPU的昂贵机器上表现良好,但在例如手机与嵌入式之类的小设备上就坑爹了。

为了简化网络,张教授尝试通过简明扼要的二进制权重估计CNN的精确近似值。教授需要你的帮助。

简而言之,先给你一个加权向量W=(w1,w2,...,wn)。张教授想找出一个二进制向量B=(b1,b2,...,bn) (bi∈{+,−})与一个缩放系数α≥0使得||W - αB||^2最小。

注意||·||表示欧几里德范数(即||X||^ = (x1^ + ... xn^),其中X=(x1,x2,...,xn))。

CN

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).
多组测试用例。输入的第一行为一个整数T,表示测试用例的数量。对于每个测试用例:

第一行为一个整数n (≤n≤)——向量的长度。下一行有n个整数w1,w2,...,wn (−≤wi≤)。

CN

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.

对于每组测试用例,输出以不可约分数"p/q"的表示||W - αB||^2最小值,此处p与q为整数,q>。

CN

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

题解

  一般的公式推倒

  此时已基本是一元二次不等式,设

 

  带入,得

  因为opt>=0,所以要使opt最小,则b最大。

代码 C++

 #include <cstdio>
#include <cstdlib>
#define mx 100005
__int64 GCD(__int64 a, __int64 b){
__int64 c;
while (c = a%b) a = b, b = c;
return b;
}
int main(){
__int64 t, n, i, tmp, c, b;
for (scanf("%I64d", &t); t; --t){
c = b = tmp = ;
for (i = scanf("%I64d", &n); i <= n; ++i){
scanf("%I64d", &tmp);
c += tmp * tmp;
b += abs(tmp);
}
c = c*n - b*b;
tmp = GCD(c, n);
printf("%I64d/%I64d\n", c / tmp, n / tmp);
}
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 水题

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

  3. HDU 5734 Acperience

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

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

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

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

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

  6. HDU 5734 Acperience(数学推导)

    Problem Description Deep neural networks (DNN) have shown significant improvements in several applic ...

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

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

  8. HDU 5734 A - Acperience

    http://acm.hdu.edu.cn/showproblem.php?pid=5734 Problem Description Deep neural networks (DNN) have s ...

  9. Acperience HDU - 5734

    Deep neural networks (DNN) have shown significant improvements in several application domains includ ...

随机推荐

  1. windows下安装 sphinx 数据库全文搜索引擎

    此次演示的环境是:win7系统,64位,php5.4.x,apache sphinx,斯芬克斯(英语不好的同学可以直接读这个音),意狮身人面像 特点:创建索引速度快,3分钟左右能创建100万条记录的索 ...

  2. Android (二维码)关于java.lang.UnsatisfiedLinkError的小案例

    在许多项目中我们都会用到第三方动态库.so文件,但是往往会引来很多烦恼,比如:Java.lang.UnsatisfiedLinkError - ::-/com.ishow.scan E/Android ...

  3. px、em、rem区别介绍

    px.em.rem区别介绍 PX px像素(Pixel).相对长度单位.像素px是相对于显示器屏幕分辨率而言的. PX特点 1. IE无法调整那些使用px作为单位的字体大小: 2. 国外的大部分网站能 ...

  4. RDIFramework.NET ━ 9.13 系统日志与系统异常管理 ━ Web部分

    RDIFramework.NET ━ .NET快速信息化系统开发框架 9.13  系统日志与系统异常管理 -Web部分  一个软件在投入运行时不可能没有任何异常,在软件发生异常时及时的记录下来,也好我 ...

  5. 从零开始学Linux[二]:常用操作:用户组、进程、网络、ssh

    摘要:Linux基础学习:创建用户组和用户.软件包管理.磁盘管理.进程管理.前后台进程的切换.网络配置.浏览网页.远程登录ssh 第一节,主要介绍一些简单命令,这节介绍一些日常操作. 1.创建用户组和 ...

  6. css字体样式(Font Style),属性

    css字体样式(Font Style),属性   css字体样式(Font Style)是网页中不可或缺的样式属性之一,有了字体样式,我们的网页才能变得更加美观,因此字体样式属性也就成为了每一位设计者 ...

  7. 《zw版·Halcon-delphi系列原创教程》 Halcon分类函数013,shape模型

    <zw版·Halcon-delphi系列原创教程> Halcon分类函数013,shape模型 为方便阅读,在不影响说明的前提下,笔者对函数进行了简化: :: 用符号“**”,替换:“pr ...

  8. 《zw版·Halcon-delphi系列原创教程》 Halcon分类函数003·contour,轮廓处理

    <zw版·Halcon-delphi系列原创教程> Halcon分类函数003·contour,轮廓处理 为方便阅读,在不影响说明的前提下,笔者对函数进行了简化: :: 用符号“**”,替 ...

  9. Java运行环境的配置

    Make sure you do not use the trailing semicolon: This will not work: set JAVA_HOME=C:\Program Files ...

  10. 记录对依赖注入的小小理解和autofac的简单封装

    首先,我不是一个开发者,只是业余学习者.其次我的文化水平很低,写这个主要是记录一下当前对于这块的理解,因为对于一个低水平 的业余学习者来说,忘记是很平常的事,因为接触.应用的少,现在理解,可能过段时间 ...