【HDU5734 2016 Multi-University Training Contest 2A】【公式代入推导】Acperience n维向量各有加减最小模长

Acperience

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 993    Accepted Submission(s): 532


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αB2  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   (1n100000)  -- the length of the vector. The next line contains   n  integers:   w1,w2,...,wn   (10000wi10000) .
 

Output
For each test case, output the minimum value of   WαB2  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
 

Author
zimpha
 

Source

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<ctype.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b>a)a = b; }
template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b<a)a = b; }
const int N = 100010, M = 0, Z = 1e9 + 7, ms63 = 0x3f3f3f3f;
int casenum, casei;
LL n;
LL a[N];
LL gcd(LL x, LL y)
{
	return y == 0 ? x : gcd(y, x%y);
}
/*
n * ∑(wi^2) - (∑|wi|)^2 (1e18-1e16)
-----------------------------------
                n
*/
int main()
{
	scanf("%d", &casenum);
	for (casei = 1; casei <= casenum; ++casei)
	{	
		LL a = 0;
		LL b = 0;
		scanf("%d", &n);
		for (int i = 1; i <= n; ++i)
		{
			LL x; scanf("%lld", &x);
			a += x*x;
			b += abs(x);
		}
		LL top = n*a - b*b;
		LL bot = n;
		LL g = gcd(top, bot);
		printf("%lld/%lld\n", top/g, bot/g);
	}
	return 0;
}
/*
【trick&&吐槽】
1,很多题目看起来很冗杂,
其实我们读重点的话,就会发现题目是可以入手的。
比赛的时候也不能放弃题目阅读,往往藏了很多简单题。

2,一定要注意数据上限,队友推出了一个爆LL的错误公式

3,java做大数运算是很耗时间的,尽量规避。

【题意】
给你一个n维向量a,
然后我们希望对a向量的每个维度都加减一个相同的值,
使得得到的目标向量b的模尽可能小。

【类型】
公式化简

【分析】
如何做公式化简?
先一股脑地做代入!
(w1-ab1, w2-ab2, ... , wn-ab3),然后得到——
原式=
 (w1-ab1)^2
+(w2-ab2)^2
+(w3-ab3)^2
...
+(wn-abn)^2
=(w1^2+...+wn^2)[定值] + (a^2)*(b1^2+b2^2+...+bn^2) - 2a(w1b1+w2b2+...+wnbn)
=[定值]+(a^2)*n-(2a)*(w1b1+w2b2+...+wnbn)
我们希望使其尽可能小,
显然 要使得(w1b1+w2b2+...+wnbn)尽可能大,这个很容易做的。使其变为了给定的定值。

然后,我们最后需要考虑的是一个
(x^2)*n-2x*[定值]+[定值]的一元二次方程。
显然,其最小值为
    b^2                (∑|wi|)^2           n * ∑(wi^2) - (∑|wi|)^2 (1e18-1e16)
c- ----  = ∑(wi^2) -  ----------      =  ----------------------------
    4a                   n                              n

【时间复杂度&&优化】
O(n)

*/


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android是一种基于Linux内核(不包含GNU组件)的自由及开放源代码的移动操作系统,主要应用于移动设备,如智能手机和平板电脑。该系统最初由安迪·鲁宾开发,后被Google公司收购并注资,随后与多家硬件制造商、软件开发商及电信营运商共同研发改良。 Android操作系统的特点包括: 开放源代码:Android系统采用开放源代码模式,允许开发者自由访问、修改和定制操作系统,这促进了技术的创新和发展,使得Android系统具有高度的灵活性和可定制性。 多任务处理:Android允许用户同时运行多个应用程序,并且可以轻松地在不同应用程序之间切换,提高了效率和便利性。 丰富的应用生态系统:Android系统拥有庞大的应用程序生态系统,用户可以从Google Play商店或其他第三方应用市场下载和安装各种各样的应用程序,满足各种需求。 可定制性:Android操作系统可以根据用户的个人喜好进行定制,用户可以更改主题、小部件和图标等,以使其界面更符合个人风格和偏好。 多种设备支持:Android操作系统可以运行在多种不同类型的设备上,包括手机、平板电脑、智能电视、汽车导航系统等。 此外,Android系统还有一些常见的问题,如应用崩溃、电池耗电过快、Wi-Fi连接问题、存储空间不足、更新问题等。针对这些问题,用户可以尝试一些基本的解决方法,如清除应用缓存和数据、降低屏幕亮度、关闭没有使用的连接和传感器、限制后台运行的应用、删除不需要的文件和应用等。 随着Android系统的不断发展,其功能和性能也在不断提升。例如,最新的Android版本引入了更多的安全性和隐私保护功能,以及更流畅的用户界面和更强大的性能。此外,Android系统也在不断探索新的应用场景,如智能家居、虚拟现实、人工智能等领域。 总之,Android系统是一种功能强大、灵活可定制、拥有丰富应用生态系统的移动操作系统,在全球范围内拥有广泛的用户基础。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值