Acperience
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 748 Accepted Submission(s): 404
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
一元二次不等式最值公式
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<stack>
using namespace std;
const int maxn=100010;
typedef long long LL;
LL num[maxn];
LL gcd(LL a,LL b){
return b==0?a:gcd(b,a%b);
}
int main()
{
int t,n;cin>>t;
while(t--){
scanf("%d",&n);
LL sum=0,qsum=0;
for(int i=1;i<=n;++i){
scanf("%lld",&num[i]);
sum+=abs(num[i]);qsum+=num[i]*num[i];
}
//LL ans = (4*a*c-b*b)/4*a;
LL u=(4*qsum*n-4*sum*sum);
LL d=4*n;
LL GCD=gcd(u,d);
if(u==0){
printf("0/1\n");
}
else {
printf("%lld/%lld\n",u/GCD,d/GCD);
}
}
return 0;
}
It's All In The Mind
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 855 Accepted Submission(s): 399
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.
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 .
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
2 2 0 3 1 3 1
Sample Output
1/1 200/201
Author
zimpha
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<stack>
using namespace std;
int num[110];
int gcd(int a,int b){
return b==0?a:gcd(b,a%b);
}
int main()
{
int t,n,m;cin>>t;
while(t--){
scanf("%d%d",&n,&m);
memset(num,-1,sizeof(num));
int x,y;
for(int i=1;i<=m;++i){
scanf("%d%d",&x,&y);
num[x]=y;
}
if(num[1]!=-1){
if(num[2]==-1){
num[2]=num[1];
}
}
else {
num[1]=100;
if(num[2]==-1)num[2]=100;
}
int k=0;
for(int i=n;i>=3;--i){
if(num[i]==-1)num[i]=k;
else k=num[i];
}
int u=num[1]+num[2],d=0;
for(int i=1;i<=n;++i){
d+=num[i];
}
int GCD=gcd(u,d);
printf("%d/%d\n",u/GCD,d/GCD);
}
return 0;
}
Keep On Movin
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 533 Accepted Submission(s): 386
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
题意:给出N种不同字符及每种字符的数量求能够组成的回文字符串的长度的最小值最大化
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<stack>
using namespace std;
const int maxn=100010;
int num[maxn];
int main()
{
int t,n;cin>>t;
while(t--){
scanf("%d",&n);
int odd=0,sum=0;
for(int i=1;i<=n;++i){
scanf("%d",&num[i]);
sum+=num[i];
if(num[i]&1)odd++;
}
if(odd==0){
printf("%d\n",sum);
}
else {
int even=(sum-odd)/2;
printf("%d\n",(even/odd)*2+1);
}
}
return 0;
}
La Vie en rose
Time Limit: 14000/7000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 878 Accepted Submission(s): 474
Problem Description
Professor Zhang would like to solve the multiple pattern matching problem, but he only has only one pattern string
p=p1p2...pm
. So, he wants to generate as many as possible pattern strings from
p
using the following method:
1. select some indices i1,i2,...,ik such that 1≤i1<i2<...<ik<|p| and |ij−ij+1|>1 for all 1≤j<k .
2. swap pij and pij+1 for all 1≤j≤k .
Now, for a given a string s=s1s2...sn , Professor Zhang wants to find all occurrences of all the generated patterns in s .
1. select some indices i1,i2,...,ik such that 1≤i1<i2<...<ik<|p| and |ij−ij+1|>1 for all 1≤j<k .
2. swap pij and pij+1 for all 1≤j≤k .
Now, for a given a string s=s1s2...sn , Professor Zhang wants to find all occurrences of all the generated patterns in s .
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 two integers n and m (1≤n≤105,1≤m≤min{5000,n}) -- the length of s and p .
The second line contains the string s and the third line contains the string p . Both the strings consist of only lowercase English letters.
The first line contains two integers n and m (1≤n≤105,1≤m≤min{5000,n}) -- the length of s and p .
The second line contains the string s and the third line contains the string p . Both the strings consist of only lowercase English letters.
Output
For each test case, output a binary string of length
n
. The
i
-th character is "1" if and only if the substring
sisi+1...si+m−1
is one of the generated patterns.
Sample Input
3 4 1 abac a 4 2 aaaa aa 9 3 abcbacacb abc
Sample Output
1010 1110 100100100
Author
zimpha
Source
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#define PI acos(-1.0)
#define CLR(a, b) memset(a, (b), sizeof(a))
#define fi first
#define se second
#define ll o<<1
#define rr o<<1|1
using namespace std;
typedef long long LL;
char str[100010];
char p[5100];
int n,m;
int main() {
int t;cin>>t;
while(t--)
{
scanf("%d%d",&n,&m);
scanf("%s%s",str,p);
for(int i=0;str[i];++i){
bool flag=true;int pos=i;
for(int j=0;p[j];++j){
if(str[pos] != p[j]){
if(str[pos+1] == p[j] && p[j+1] == str[pos]){
j++; pos++;
}
else {
flag=false;break;
}
}
pos++;
}
printf("%d",flag);
}
printf("\n");
}
return 0;
}