Acperience
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 972 Accepted Submission(s): 517
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) ).
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) .
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
Author
zimpha
Source
化为w1 ^2+w2 ^2+w3 ^2+...+wn ^2+n b^2 - 2sb
b在s/n处使函数最小------
记得分子分母及时化简-----不然爆long long
代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define LL long long
LL gcd(LL dd,LL xx)
{
LL c;
if (dd<xx)
{
c=dd;dd=xx;xx=c;
}
return dd%xx==0? xx:gcd(xx,dd%xx);
}
LL shu[1212120];
void s()
{
LL s=0,n;
scanf("%lld",&n);
for (int i=0;i<n;i++)
{
scanf("%lld",&shu[i]);
if (shu[i]<0)
shu[i]=0-shu[i];
s+=shu[i];
}
sort(shu,shu+n);
if (shu[0]==shu[n-1])
{
printf("0/1\n");
return ;
}
LL ss=0,mu,zhi;
for (int i=0;i<n;i++)
ss+=shu[i]*shu[i];
zhi=s*s;mu=n;
// printf("%lld %lld %lld\n",zhi,mu,ss);
LL lp=gcd(zhi,mu);
zhi/=lp;mu/=lp;
zhi=mu*ss-zhi;
lp=gcd(zhi,mu);
zhi/=lp;mu/=lp;
printf("%lld/%lld\n",zhi,mu);
}
int main()
{
int n;scanf("%d",&n);
while (n--)
s();
return 0;
}
|
It's All In The MindTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1119 Accepted Submission(s): 546
Problem Description
Professor Zhang has a number sequence
a1,a2,...,an
. However, the sequence is not complete and some elements are missing. Fortunately, Professor Zhang remembers some properties of the sequence:
1. For every i∈{1,2,...,n} , 0≤ai≤100 . 2. The sequence is non-increasing, i.e. a1≥a2≥...≥an . 3. The sum of all elements in the sequence is not zero. Professor Zhang wants to know the maximum value of a1+a2∑ni=1ai among all the possible sequences.
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 contains two integers n and m (2≤n≤100,0≤m≤n) -- the length of the sequence and the number of known elements. In the next m lines, each contains two integers xi and yi (1≤xi≤n,0≤yi≤100,xi<xi+1,yi≥yi+1) , indicating that axi=yi .
Output
For each test case, output the answer as an irreducible fraction "
p
/
q
", where
p
,
q
are integers,
q>0
.
Sample Input
Sample Output
Author
zimpha
Source
|
让a1+a2尽可能的大-----
s尽可能的小
代码:
#include<cstdio>
#include<cstring>
int gcd(int dd,int xx)
{
return dd%xx==0? xx:gcd(xx,dd%xx);
}
void s()
{
int n,m,a,b;int fafe[120];int shu[120];
memset(fafe,true,sizeof(fafe));
scanf("%d%d",&n,&m);
while (m--)
{
scanf("%d%d",&a,&b);
shu[a]=b;
fafe[a]=false;
}
if (fafe[1]&&fafe[2])
{
shu[1]=shu[2]=100;
}
else if (fafe[1])
{
shu[1]=100;
}
else if (fafe[2])
shu[2]=shu[1];
int mi=0;
for (int i=n;i>2;i--)
{
if (!fafe[i])
mi=shu[i];
else
shu[i]=mi;
}
int zhi=shu[1]+shu[2];
int mu=0;
for (int i=1;i<=n;i++)
mu+=shu[i];
if (zhi==0)
{
printf("0/1\n");
return ;
}
int lp=gcd(mu,zhi);
mu/=lp;zhi/=lp;
printf("%d/%d\n",zhi,mu);
}
int main()
{
int n;scanf("%d",&n);
while (n--)
s();
return 0;
}
Keep On Movin
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 726 Accepted Submission(s): 526
Problem Description
Professor Zhang has kinds of characters and the quantity of the
i
-th character is
ai
. Professor Zhang wants to use all the characters build several palindromic strings. He also wants to maximize the length of the shortest palindromic string.
For example, there are 4 kinds of characters denoted as 'a', 'b', 'c', 'd' and the quantity of each character is {2,3,2,2} . Professor Zhang can build {"acdbbbdca"}, {"abbba", "cddc"}, {"aca", "bbb", "dcd"}, or {"acdbdca", "bb"}. The first is the optimal solution where the length of the shortest palindromic string is 9.
Note that a string is called palindromic if it can be read the same way in either direction.
For example, there are 4 kinds of characters denoted as 'a', 'b', 'c', 'd' and the quantity of each character is {2,3,2,2} . Professor Zhang can build {"acdbbbdca"}, {"abbba", "cddc"}, {"aca", "bbb", "dcd"}, or {"acdbdca", "bb"}. The first is the optimal solution where the length of the shortest palindromic string is 9.
Note that a string is called palindromic if it can be read the same way in either direction.
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 integer n (1≤n≤105) -- the number of kinds of characters. The second line contains n integers a1,a2,...,an (0≤ai≤104) .
The first line contains an integer n (1≤n≤105) -- the number of kinds of characters. The second line contains n integers a1,a2,...,an (0≤ai≤104) .
Output
For each test case, output an integer denoting the answer.
Sample Input
4 4 1 1 2 4 3 2 2 2 5 1 1 1 1 1 5 1 1 2 2 3
Sample Output
3 6 1 3
Author
zimpha
Source
看字符奇数的个数====然后让偶数尽可能的平均补奇数---
代码“:
#include<cstdio>
void s()
{
int n,c;scanf("%d",&n);
int a=0,b=0;
while (n--)
{
scanf("%d",&c);
a+=c%2;
b+=c/2;
}
if (a)
c=1+b/a*2;
else
c=b*2;
printf("%d\n",c);
}
int main()
{
int n;scanf("%d",&n);
while (n--)
s();
return 0;
}