HDU 5734 Acperience(数学推导)
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.
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
3
4
1 2 3 4
4
2 2 2 2
5
5 6 2 3 4
5/1
0/1
10/1
题意
给你一个n维向量w,求∥W−αB∥2的最小值,其中B=(b1,b2,...,bn) (bi∈{+1,−1}),α≥0
题解
开始误以为是平均数最小,WA了几次后开始推式子
min(∥w−αb∥2)=min(∑(wi2-2αbiwi+α2bi2))
由于bi∈{+1,−1},易得bi*w≥0
=min(∑(wi2-2α|wi|+α2))=min(∑(α2-2α|wi|+wi2))=min(nα2-2α∑|wi|+∑wi2)
可知当α=∑|wi|/n时函数取到min
代入化简得=-(∑|wi|)2/n+∑wi2
通分=(n∑wi2-(∑|wi|)2)/n
gc=gcd(n∑wi2-(∑|wi|)2,n)
所以p=(n∑wi2-(∑|wi|)2)/gc,q=n/gc
代码
#include<bits/stdc++.h>
using namespace std; #define ll long long
const int maxn=1e5+;
int a[maxn];
int main()
{
int t,n;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
ll sum=,ac=;
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
sum+=abs(a[i]);
ac+=a[i]*1LL*a[i];
}
ll gc=__gcd(ac*n-sum*sum,1LL*n);
printf("%lld/%lld\n",(ac*n-sum*sum)/gc,n/gc);
}
return ;
}
HDU 5734 Acperience(数学推导)的更多相关文章
- HDU 5734 Acperience (推导)
Acperience 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5734 Description Deep neural networks (DN ...
- HDU 5734 Acperience ( 数学公式推导、一元二次方程 )
题目链接 题意 : 给出 n 维向量 W.要你构造一个 n 维向量 B = ( b1.b2.b3 ..... ) ( bi ∈ { +1, -1 } ) .然后求出对于一个常数 α > 0 使得 ...
- 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 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.5211.Mutiple(数学推导 && 在logn的时间内求一个数的所有因子)
Mutiple Accepts: 476 Submissions: 1025 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 6553 ...
- HDU 5734 Acperience (公式推导) 2016杭电多校联合第二场
题目:传送门. #include <iostream> #include <algorithm> #include <cstdio> #include <cs ...
- HDU 5984 题解 数学推导 期望
Let’s talking about something of eating a pocky. Here is a Decorer Pocky, with colorful decorative s ...
随机推荐
- socat管理haproxy以及haproxy调优
Unix套接字命令(Unix Socket commands) socat是一个多功能的网络工具,名字来由是“Socket CAT”,可以看作是netcat的N倍加强版,socat的官方网站:http ...
- laravel whereNotIn where子查詢
子查詢寫法 $stores = Stores::select('id','name')->whereNotIn('id', function ($query) use($id){ $query- ...
- Eclipse Build path
Build Path用于设置Java的构建路径,管理Java工程所包含的资源,使工程结构清晰合理. 包括以下几项: Source Source包括 source folder和output folde ...
- django 路由系统中name应用
作用:对URL路由关系进行命名, ***** 以后可以根据此名称生成自己想要的URL ***** name的两大应用 url(r'^asdfasdfasdf/', views.index, name= ...
- read()、write()返回 Input/output error, Device or resource busy解决
遇到的问题,通过I2C总线读.写(read.write)fs8816加密芯片,报错如下: read str failed,error= Input/output error! write str fa ...
- oracle user_tables没有新创建的表的问题
oracle 新创建表后,在user_tables没有,在user_tab_columns也没有,暂时未找到办法
- Pycharm初始创建项目和环境搭建
Pycharm确实是一个非常不错的Python开发IDE,尤其对于初学者而言. 打开新建项目 1.选择新建一个Pure Python项目,新建项目路径可以在Location处选择. 2.Project ...
- Dapper/SqlMapper映射对应问题
Dapper, a light weight object mapper for ADO.NET 轻量级orm辅助类,不用配置,直接引入一个cs文件或者引入其dll就能使用. 使用连接对象的query ...
- [UE4]Scale Box:缩放容器
一.Scale Box只能有一个子控件,再拖放一控件进去是不行的. 二.Scale Box缩放保持长宽比例 三. Scale Box.Strectching.Strectch:拉伸设置. Scale ...
- Unity Shader Graph(二)Dissolve Effect
此篇文章记录Dissolve Effect(溶解特效)的制作过程 软件环境 Unity 2018.1.2f1 Packages: Lightweight Render Pipeline 1.1.11 ...