Acperience HDU - 5734
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)W=(w1,w2,...,wn). Professor Zhang would like to find a binary vector B=(b1,b2,...,bn)B=(b1,b2,...,bn) (bi∈{+1,−1})(bi∈{+1,−1}) and a scaling factor α≥0α≥0in such a manner that ∥W−αB∥2‖W−αB‖2 is minimum.
Note that ∥⋅∥‖⋅‖ denotes the Euclidean norm (i.e. ∥X∥=x21+⋯+x2n−−−−−−−−−−−√‖X‖=x12+⋯+xn2, where X=(x1,x2,...,xn)X=(x1,x2,...,xn)).
InputThere are multiple test cases. The first line of input contains an integer TT, indicating the number of test cases. For each test case:
The first line contains an integers nn (1≤n≤100000)(1≤n≤100000) -- the length of the vector. The next line contains nn integers: w1,w2,...,wnw1,w2,...,wn (−10000≤wi≤10000)(−10000≤wi≤10000).OutputFor each test case, output the minimum value of ∥W−αB∥2‖W−αB‖2 as an irreducible fraction "pp/qq" where pp, qq are integers, q>0q>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* (x1^2+x2^2+…….+xn^2) - sum*sum
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include <vector>
#include<math.h>
using namespace std;
long long gcd(long long a,long long b)
{
if (a==) return b;
else gcd(b%a,a);
}
int main()
{
int t;
while(scanf("%d",&t)!=EOF){
while(t--){
int n,a;
scanf("%d",&n);
long long ans=,cnt=,sum=;
for (int i= ;i<n ;i++){
scanf("%d",&a);
a=abs(a);
ans+=a;
cnt+=a*a;
}
ans=ans*ans;
sum=n*cnt-ans;
long long b=gcd(sum,n);
printf("%lld/%lld\n",sum/b,n/b);
}
}
return ;
}
Acperience HDU - 5734的更多相关文章
- HDU 5734 Acperience(返虚入浑)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- HDU 5734 Acperience (推导)
Acperience 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5734 Description Deep neural networks (DN ...
- 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 A - Acperience
http://acm.hdu.edu.cn/showproblem.php?pid=5734 Problem Description Deep neural networks (DNN) have s ...
- 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(数学推导)
Problem Description Deep neural networks (DNN) have shown significant improvements in several applic ...
- HDU 5734 Acperience ( 数学公式推导、一元二次方程 )
题目链接 题意 : 给出 n 维向量 W.要你构造一个 n 维向量 B = ( b1.b2.b3 ..... ) ( bi ∈ { +1, -1 } ) .然后求出对于一个常数 α > 0 使得 ...
随机推荐
- web前端性能优化问题
常用的几大优化解决: 页面内容的优化 减少http请求 途径: 1>启用http/2--越来越多的浏览器都开始支持 HTTP/2.HTTP/2 为同一服务器的并发连接问题带来了很多好处.换句话说 ...
- BZOJ 4698: Sdoi2008 Sandy的卡片 [后缀自动机]
4698: Sdoi2008 Sandy的卡片 题意:差分后就是多个串LCS SAM+map大法好 模板打错 智力-2 #include <iostream> #include <c ...
- BZOJ 1415: [Noi2005]聪聪和可可 [DP 概率]
传送门 题意:小兔子乖乖~~~ 题意·真:无向图吗,聪抓可,每个时间聪先走可后走,聪一次可以走两步,朝着里可最近且点编号最小的方向:可一次只一步,等概率走向相邻的点或不走 求聪抓住可的期望时间 和游走 ...
- ubuntu14.04安装、NVIDIA显卡驱动安装及CUDA8.0、Cudnn5.1的环境搭建
安装环境:hp-Z440工作站.64位Ubuntu14.04(64位Ubuntu16.04).Cuda8.0.Cudnn5.1.Nvidia GeForce GT 705.Tesla K40c 本文可 ...
- JSON入门看这一篇就够了
什么是JSON JSON:JavaScript Object Notation [JavaScript 对象表示法] JSON 是存储和交换文本信息的语法.类似 XML. JSON采用完全独立于任何程 ...
- 蛋疼的_after_insert
这两天在做一个素材类的网站,用的依旧是TP3.2,在做到发布话题这部分的时候,发现了一个问题,我在添加话题的时候在模型里写了个钩子函数_after_insert(),希望在新增话题数据之后同时将话题的 ...
- es6 Object.assign
ES6 Object.assign 一.基本用法 Object.assign方法用来将源对象(source)的所有可枚举属性,复制到目标对象(target).它至少需要两个对象作为参数,第一个参数是目 ...
- 教我徒弟Android开发入门(二)
前言: 上一期实现了简单的QQ登录效果,这一期继续对上一期进行扩展 本期的知识点: Toast弹窗,三种方法实现按钮的点击事件监听 正文: Toast弹窗其实很简单,在Android Studio ...
- .NET平台开源项目速览(19)Power BI神器DAX Studio
PowerBI更新频繁,已经有点更不上的节奏,一直在关注和学习中,基本的一些操作大概是没问题,更重要的是注重Power Query,M函数,以及DAX的使用,这才是核心. 上个月研究了DAX的一些 ...
- 《HelloGitHub》第 23 期
公告 新的一年,不忘初心,从新开始.加油! <HelloGitHub>第 23 期 兴趣是最好的老师,HelloGitHub 就是帮你找到兴趣! 简介 分享 GitHub 上有趣.入门级的 ...