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, 查了一下午没看出原因...
更合理的办法是通过展开原式来推导,详见官方题解:
以后遇到关于期望、最大最小值等式子时,尽可能多推导几步再看. 不要上来就找规律导致问题复杂.

##代码:
``` 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 (推导)的更多相关文章
- HDU 5734 Acperience(返虚入浑)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- HDU 5734 Acperience(数学推导)
Problem Description Deep neural networks (DNN) have shown significant improvements in several applic ...
- hdu 5734 Acperience 水题
Acperience 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5734 Description Deep neural networks (DN ...
- HDU 5734 Acperience
Acperience Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- hdu 5734 Acperience(2016多校第二场)
Acperience Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- HDU 5734 Acperience (公式推导) 2016杭电多校联合第二场
题目:传送门. #include <iostream> #include <algorithm> #include <cstdio> #include <cs ...
- HDU 5734 Acperience ( 数学公式推导、一元二次方程 )
题目链接 题意 : 给出 n 维向量 W.要你构造一个 n 维向量 B = ( b1.b2.b3 ..... ) ( bi ∈ { +1, -1 } ) .然后求出对于一个常数 α > 0 使得 ...
- HDU 5734 A - Acperience
http://acm.hdu.edu.cn/showproblem.php?pid=5734 Problem Description Deep neural networks (DNN) have s ...
- Acperience HDU - 5734
Deep neural networks (DNN) have shown significant improvements in several application domains includ ...
随机推荐
- option配置
wildignore:用来设置忽略的文件匹配模式,shell模式
- [UESTC1059]秋实大哥与小朋友(线段树, 离散化)
题目链接:http://acm.uestc.edu.cn/#/problem/show/1059 普通线段树+离散化,关键是……离散化后建树和查询都要按照基本法!!!RE了不知道多少次………………我真 ...
- python学习笔记之初识Python
一直听说python语音的简单易用而又强大,今天终于忍不住借本书,开始接触接触一下它,下面结合书本和自己的一些体会,写一下刚刚接触python的东西,重点写一些和C++有区别的地方. (1)输入inp ...
- Effective C++学习笔记 条款05:了解C++默默编写并调用的哪些函数
一.如果用户没有提供构造函数.copy构造函数.copy assignment操作符和析构函数,当且仅当这些函数被需要的时候,编译器才会帮你创建出来.编译器生成的这些函数都是public且inline ...
- zlib代码生成
1.主页下载zlib-1.2.8的source code的压缩包:F:\Develop Tools\zlib-1.2.8 2.下载安装cmake-2.8.1-win32-x86 3.用cmake生成z ...
- hdu 4968 Improving the GPA (水 暴力枚举)
题目链接 题意:给平均成绩和科目数,求可能的最大学分和最小学分. 分析: 枚举一下,可以达到复杂度可以达到10^4,我下面的代码是10^5,可以把最后一个循环撤掉. 刚开始以为枚举档次的话是5^10, ...
- hdu4939 动态规划
经典动态规划 无需单独枚举最后红塔的数量,因为对于dp[i][j],对于红塔的影响仅局限于i,j两个变量,与其前面塔排列无关,故二维动态规划即可. #include <cstdio> #i ...
- 函数 page_dir_get_n_heap
查看某page中含有的记录个数 #define PAGE_N_HEAP 4 /* number of records in the heap, bit =flag: new-style compact ...
- UVa 11235 (RMQ) Frequent values
范围最值问题,O(nlogn)的预处理,O(1)的查询. 这个题就是先对这些数列进行游程编码,重复的元素只记录下重复的次数. 对于所查询的[L, R]如果它完全覆盖了某些连续的重复片段,那么查询的就是 ...
- 使用Java VisualVM监控远程JVM
我们经常需要对我们的开发的软件做各种测试, 软件对系统资源的使用情况更是不可少, 目前有多个监控工具, 相比JProfiler对系统资源尤其是内存的消耗是非常庞大,JDK1.6开始自带的VisualV ...