2016 Multi-University Training Contest 2 第一题Acperience
Acperience
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
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
题解说的很明白了,但是要注意转换成分数的时候。分数运算的时候需要先约分在进行计算,不然会爆long long,也是刚刚才留意到。。
#include <cstdio>
#include <iostream>
using namespace std;
#define LL long long
LL n;
LL x;
LL gcd(LL a,LL b)
{
return b== ? a:gcd(b,a%b);
}
int main()
{
LL T;
scanf("%d", &T);
while(T --)
{
scanf("%lld", &n);
LL b = , c = ;
for(int i = ; i < n; i ++)
{
scanf("%lld", &x);
if(x>) b=b+x;
else b=b-x;
c=c+x*x;
}
LL a = n * c - b * b;
LL d = gcd(a, n);
printf("%lld/%lld\n",a/d, n/d);
}
return ;
}
2016 Multi-University Training Contest 2 第一题Acperience的更多相关文章
- 2016 Al-Baath University Training Camp Contest-1
2016 Al-Baath University Training Camp Contest-1 A题:http://codeforces.com/gym/101028/problem/A 题意:比赛 ...
- 2015多校联合训练赛 hdu 5308 I Wanna Become A 24-Point Master 2015 Multi-University Training Contest 2 构造题
I Wanna Become A 24-Point Master Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 ...
- 2015多校联合训练赛hdu 5301 Buildings 2015 Multi-University Training Contest 2 简单题
Buildings Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Tota ...
- 2016 Al-Baath University Training Camp Contest-1 E
Description ACM-SCPC-2017 is approaching every university is trying to do its best in order to be th ...
- HDU 4608 I-number 2013 Multi-University Training Contest 1 1009题
题目大意:输入一个数x,求一个对应的y,这个y满足以下条件,第一,y>x,第二,y 的各位数之和能被10整除,第三,求满足前两个条件的最小的y. 解题报告:一个模拟题,比赛的时候确没过,感觉这题 ...
- 2016 Al-Baath University Training Camp Contest-1 J
Description X is fighting beasts in the forest, in order to have a better chance to survive he's gon ...
- 2016 Al-Baath University Training Camp Contest-1 A
Description Tourist likes competitive programming and he has his own Codeforces account. He particip ...
- [CFGym101028] 2016 Al-Baath University Training Camp Contest-1
比赛链接:http://codeforces.com/gym/101028/ 由于实习,几乎没有时间刷题了.今天下午得空,断断续续做了这一套题,挺简单的. A.读完题就能出结果. /* ━━━━━┒ギ ...
- hdu4678 Mine 2013 Multi-University Training Contest 8 博弈题
Mine Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total Submi ...
随机推荐
- Spring技术内幕——深入解析Spring架构与设计原理(一)IOC实现原理
IOC的基础 下面我们从IOC/AOP开始,它们是Spring平台实现的核心部分:虽然,我们一开始大多只是在这个层面上,做一些配置和外部特性的使用工作,但对这两个核心模块工作原理和运作机制的理解,对深 ...
- 用Gitosis搭建Git服务器(经典资料)
该文档介绍了用Gitosis自己搭建Git服务器,文章来自于<Git权威指南>一书的第31章,讲述详细易懂易操作,是搭建Git服务器绝好资料! 下载地址:http://download.c ...
- Android 自定义View修炼-Android开发之自定义View开发及实例详解
在开发Android应用的过程中,难免需要自定义View,其实自定义View不难,只要了解原理,实现起来就没有那么难. 其主要原理就是继承View,重写构造方法.onDraw,(onMeasure)等 ...
- VC/MFC强制退出本进程自己,VC/MFC关闭自己
正常情况下通过关闭主窗口close或发送PostQuitMessage(WM_QUIT);消息 能关闭窗口.但如果一个进程中包括多个子线程当子线程没有结束还占用 系统资源时通过上面的两种方法是不能立即 ...
- POJ 1845 Sumdiv(因子分解+快速幂+二分求和)
题意:给你A,B,让求A^B所有的因子和模上9901 思路:A可以拆成素因子的乘积: A = p1^x1 * p2^x2 *...* pn^xn 那么A^B = p1^(B*x1) * p2^(B*x ...
- mysql left用法
LEFT(str,len) 返回字符串str的最左面len个字符. SELECT LEFT('123456789',5)
- 服務器提交協議衝突 (The server committed a protocol violation.)
---解決方法 (放在 app.config / web.config)--- <system.net> <settings> <httpWebRequest useUn ...
- javascript实现继承的6种方式
/*1.原型链继承*/ function SuperType() { this.property = true; } SuperType.prototype.getSuperValue = funct ...
- bootstrap 模态框关闭状态怎么获取
比如现在有个场景,一个事件 需要在模态框关闭之后再执行自己的逻辑,先上图: 参考官网说明:http://v3.bootcss.com/javascript/#modals-events //每次关闭模 ...
- [Json] C#ConvertJson|List转成Json|对象|集合|DataSet|DataTable|DataReader转成Json (转载)
点击下载 ConvertJson.rar 本类实现了 C#ConvertJson|List转成Json|对象|集合|DataSet|DataTable|DataReader转成Json|等功能大家先预 ...