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 ;
}

最新文章

  1. centos7安装activemq
  2. 调用C++动态链接库出现错误
  3. Google one联合联发科,国内低端智能机方案怎么办?
  4. python(25)下载文件
  5. SQL Server 2008 Windows身份验证改为混合模式身份验证
  6. https://my.oschina.net/huangyong/blog/161419
  7. Gatling的进阶二
  8. Karel运行环境配置
  9. Python元类实践--自己定义一个和collections中一样的namedtuple
  10. JavaScript基礎知識
  11. puppeteer实现线上服务器任意区域截图
  12. SQL-55 分页查询employees表,每5行一页,返回第2页的数据
  13. RabbitMQ的Q&amp;A
  14. LeetCode - Find K Closest Elements
  15. Error:No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
  16. 【Ansible 文档】【译文】网络支持
  17. Java——String类总结---18.09.27
  18. webdriver js点击无法点击的元素
  19. HDU 6201 transaction transaction transaction (树形DP)
  20. (MVVM) ListBox Binding 和 实时刷新

热门文章

  1. Android基础知识回顾
  2. leetcode__Convert Sorted List to Binary Search Tree
  3. lucene索引并搜索mysql数据库[转]
  4. Android-打反编译工具的一种方法
  5. CentOS7上GitHub/GitLab多帐号管理SSH Key
  6. HDFS的Java客户端操作代码(HDFS删除文件或目录)
  7. gitcafe 使用hexo搭建博客
  8. php快速排序
  9. 在eclipse中部署发布web项目 和 更改eclipseweb项目发布的路径
  10. C#语法糖之第四篇: 扩展方法