hdu 5734 Acperience (数学)
2016-07-23 09:17
381 查看
Acperience
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 747 Accepted Submission(s): 403
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∥=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
题意:给你n个w,n个B,B只能取-1或1,让你找一个α,使得∑ni=1||wi−αBi||2取最小值.
思路:首先,我们来化简题中得到式子,化简得:
∑i=1n||wi−αBi||2=∑i=1nw2i+∑i=1nα2B2i+∑i=1n−2αBi
设sum为w的和,ksum为w的平方和,α为x,则方程为:nx2−2sumx+ksum,这样就转换成了一个开口向上的一元二次方程式求其最小值的问题,直接求就好了,注意求sum的时候要取|w|的和,因为B可以取-1或者1,所以说B可根据w的正负调整正负。最后上下化简就可以了。
ac代码:
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 747 Accepted Submission(s): 403
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∥=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
题意:给你n个w,n个B,B只能取-1或1,让你找一个α,使得∑ni=1||wi−αBi||2取最小值.
思路:首先,我们来化简题中得到式子,化简得:
∑i=1n||wi−αBi||2=∑i=1nw2i+∑i=1nα2B2i+∑i=1n−2αBi
设sum为w的和,ksum为w的平方和,α为x,则方程为:nx2−2sumx+ksum,这样就转换成了一个开口向上的一元二次方程式求其最小值的问题,直接求就好了,注意求sum的时候要取|w|的和,因为B可以取-1或者1,所以说B可根据w的正负调整正负。最后上下化简就可以了。
ac代码:
#include<stdio.h> #include<math.h> #include<string.h> #include<stack> #include<set> #include<map> #include<queue> #include<vector> #include<iostream> #include<algorithm> #define MAXN 1010000 #define LL long long #define ll __int64 #define INF 0x7fffffff #define mem(x) memset(x,0,sizeof(x)) #define PI acos(-1) #define eps 1e-8 using namespace std; ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} ll lcm(ll a,ll b){return a/gcd(a,b)*b;} ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;} double dpow(double a,ll b){double ans=1.0;while(b){if(b%2)ans=ans*a;a=a*a;b/=2;}return ans;} //head ll sum,ksum; int main() { int t;scanf("%d",&t); while(t--) { int n;scanf("%d",&n); sum=0;ksum=0; for(int i=1;i<=n;i++) { int a;scanf("%d",&a); sum+=abs(a); ksum+=a*a; } ll a=n,b=-2*sum,c=ksum; ll up=n*ksum-sum*sum,down=n; ll k=gcd(up,down); printf("%I64d/%I64d\n",up/k,down/k); } return 0; }
相关文章推荐
- Android--水平进度条对话框
- 复习(数据结构):队列:c语言
- java发送qq邮件进行验证
- 【机器学习】windows版caffe深度学习库编译
- POJ1328Radar Installation
- android studio出现Error:compileSdkVersion android-x requires compiling with JDK 7问题
- [2016/7/23][usaco 2.2]Subset Sums
- cin循环输入控制问题
- 建设一套直播CDN、直播平台到底有多难?
- 贪心算法
- 删除右键"上传到有道云笔记"
- 杭电ACM 2031,2057 进制转化问题
- 手游直播到底难在哪里?
- Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exc
- [李景山php]每天laravel-20160925|Pipeline.php
- 如何架构大规模云端直播录制集群?
- golang image图片处理示例
- 人见人爱A-B hd 2034
- hdoj4883TIANKENG’s restaurant
- 萌妹网红陪看球,欧洲杯直播技术探秘