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 


1 2 3 4 

2 2 2 2 

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的更多相关文章

  1. 2016 Al-Baath University Training Camp Contest-1

    2016 Al-Baath University Training Camp Contest-1 A题:http://codeforces.com/gym/101028/problem/A 题意:比赛 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. HDU 4608 I-number 2013 Multi-University Training Contest 1 1009题

    题目大意:输入一个数x,求一个对应的y,这个y满足以下条件,第一,y>x,第二,y 的各位数之和能被10整除,第三,求满足前两个条件的最小的y. 解题报告:一个模拟题,比赛的时候确没过,感觉这题 ...

  6. 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 ...

  7. 2016 Al-Baath University Training Camp Contest-1 A

    Description Tourist likes competitive programming and he has his own Codeforces account. He particip ...

  8. [CFGym101028] 2016 Al-Baath University Training Camp Contest-1

    比赛链接:http://codeforces.com/gym/101028/ 由于实习,几乎没有时间刷题了.今天下午得空,断断续续做了这一套题,挺简单的. A.读完题就能出结果. /* ━━━━━┒ギ ...

  9. 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 ...

随机推荐

  1. 普通身份运行Tomcat

    普通身份运行Tomcat 转载1   权限分配问题 su - username -c “command”这样的形式可以使用任意一个有执行权限的用户执行 -c后边的命令. 注意,- username中间 ...

  2. Scene的实时追踪显示

    最近在处理酷跑类型游戏时,遇到一个功能需求:需要在摄像机实时追踪角色显示(Game)的同时,Scene同时实时显示NPC的位置状态等信息? 这个问题有三种解决方法,各有利弊:1)使用unity系统内置 ...

  3. chrome 全屏无法退出

    起因:chrome 按F11 全屏后,再按F11 死活无法退出全屏,关掉后,再打开chrome,自动全屏,F11无法退出全屏 系统:centos 6.3 解决:找到 chrome的用户数据存储目录,( ...

  4. 关于Parse库的配置问题

    在使用Parse的一些相关服务时候,需要下载Parse的SDK,除了需要添加相应的系统框架和库的支持 AudioToolbox.framework CFNetwork.framework CoreGr ...

  5. [rxjs] Creating An Observable with RxJS

    Create an observable var Observable = Rx.Observable; var source = Observable.create(function(observe ...

  6. Chapter 2 - How to Add a sprite

    Chapter 2 - How to Add a sprite 1. Add image resources 1.1add resources on win32 2. Add a sprite TIP ...

  7. MFC/VC++ 响应回车键的实现

    在VC++中,要实现对回车键的响应实现,一般通过截获消息来响应,即通过处理BOOL PreTranslateMessage(MSG* pMsg)这个函数来处理 实现如下: BOOL PreTransl ...

  8. ANDROID 通过监听来电去电,并弹出悬浮窗

    要监听android打电话和接电话,有一种的是通过新建一个Receiver继承自BroadcastReceiver. 还有一种也可通过PhoneStateListener来实现.今天就说说后面一种,废 ...

  9. ASP.NET 相关小知识

    后台修改前台html控件属性 添加 runat=server ,后台获取// 客户端隐藏 a.Attributes[ "style "] = "display:none ...

  10. Redis介绍

    Redis的介绍 Remote Dictionary Server(Redis)是一个基于 key-value 键值对的持久化数据库存储系统.支持多种数据结构,包括 string (字符串).list ...