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 ...
随机推荐
- Hibernate查询之Criteria查询
转自:http://www.cnblogs.com/Laupaul/archive/2012/02/15/2353194.html Criteria是一种比hql更面向对象的查询方式.Criteria ...
- SQL 主键和外键约束
SQL的主键和外键的作用: 外键取值规则:空值或参照的主键值. (1)插入非空值时,如果主键表中没有这个值,则不能插入. (2)更新时,不能改为主键表中没有的值. (3)删除主键表记录时,你可以在建外 ...
- cas改造随笔
原http://www.cnblogs.com/hellowood/archive/2010/08/05/1793364.html 键字: sso域名:cas.server.com 登陆地址(spri ...
- OpenFileDialog
打开一个文件 private void button1_Click(object sender, EventArgs e) { openFile ...
- 单片机IO口驱动能力
以STM32的IO口为例,最大的输出电流和灌入电流在芯片手册上都有说明.单个IO口一般都是十几mA到几十mA,同时总的VDD电流也有限制,大概为150mA.所以单片机驱动外设时,如果不是信号型而是功率 ...
- FPGA的JTAG下载问题
前两天做一个工频信号源项目,连续出现两块FPGA板JTAG编程failed现象,不知道原因.网上搜索了下,有帖子说如果是JTAG损坏了,用表笔打TCK,TMS,TDI,TDO,看是否存在和GND短接, ...
- C# QRCode、DataMatrix和其他条形码的生成和解码软件
今天制造了一个C#的软件,具体是用于生成二维码和条形码的,包括常用的QRCode.DataMatrix.Code128.EAN-8等等. 使用的第三方类库是Zxing.net和DataMatrix.n ...
- Python开发实战教程(8)-向网页提交获取数据
来这里找志同道合的小伙伴!↑↑↑ Python应用现在如火如荼,应用范围很广.因其效率高开发迅速的优势,快速进入编程语言排行榜前几名.本系列文章致力于可以全面系统的介绍Python语言开发知识和相关知 ...
- 关于 复制文本 然后Ctrl+V 操作的这个功能 貌似jq也没有封装。。。
/* * copy */ function copy(){ var maintext=$("#myhtml").val(); alert(maintext); copyToClip ...
- Apache common包应用集合
一.Commons BeanUtils http://jakarta.apache.org/commons/beanutils/index.html 说明:针对Bean的一个工具集.由于Bean往往是 ...