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\n", ans/tmp, n/tmp);
} return 0;

}

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

  1. HDU 5734 Acperience(返虚入浑)

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

  2. HDU 5734 Acperience(数学推导)

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

  3. hdu 5734 Acperience 水题

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

  4. HDU 5734 Acperience

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

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

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

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

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

  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. JAVA中,不同工程间的方法调用

    可以调用, 用配置构建路径的方法:点选工程1, 点击右键, 选择 Build Path(构建路径) - > Configure Build Path...(配置构建路径...)然后在弹出的窗口中 ...

  2. Ubuntu下MySQL数据库安装与配置与卸载

    安装: sudo apt-get install mysql-server mysql-client 一旦安装完成,MySQL 服务器应该自动启动.您可以在终端提示符后运行以下命令来检查 MySQL ...

  3. ASP.NET MVC 学习7、为Model Class的字段添加验证属性(validation attribuate)

    Adding Validation to the Model ,在Model中添加数据验证 参考:http://www.asp.net/mvc/tutorials/mvc-4/getting-star ...

  4. bzoj1221: [HNOI2001] 软件开发

    挖坑.我的那种建图方式应该也是合理的.然后连样例都过不了.果断意识到应该为神奇建图法... #include<cstdio> #include<cstring> #includ ...

  5. [Sciter系列] MFC下的Sciter–5.Sciter中GUI线程研究

    [Sciter系列] MFC下的Sciter–5.Sciter中GUI线程研究,目前MFC存在问题,win32没问题. 本系列文章的目的就是一步步构建出一个功能可用,接口基本完善的基于MFC框架的Sc ...

  6. Java [Leetcode 319]Bulb Switcher

    题目描述: There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off ...

  7. 云计算服务模型,第 1 部分: 基础架构即服务(IaaS)

    英文原文:Cloud computing service models, Part 1: Infrastructure as a Service 本文介绍三个云类别中的第一个:基础架构即服务(infr ...

  8. HDU 4267 A Simple Problem with Integers

    A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  9. 链表的倒数第K个节点

    题目:输入一个链表,输出该链表中倒数第K个节点.为了符合大多数人的习惯,本题从1开始计数,即链表的尾节点是倒数第1个结点. package com.edu; class LinkNode{ //定义一 ...

  10. PHP学习笔记--文件目录操作(文件上传实例)

    文件操作是每个语言必须有的,不仅仅局限于PHP,这里我们就仅用PHP进行讲解 php的文件高级操作和文件上传实例我放在文章的最后部分.--以后我还会给大家写一个PHP类似于网盘操作的例子 注意:阅读此 ...